@@ -1,311 +1,333 | |||||
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 <QGridLayout> |
|
22 | #include <QGridLayout> | |
23 | #include <QTableView> |
|
23 | #include <QTableView> | |
24 | #include <QStyledItemDelegate> |
|
24 | #include <QStyledItemDelegate> | |
25 | #include <QLineSeries> |
|
25 | #include <QLineSeries> | |
26 | #include <QSplineSeries> |
|
26 | #include <QSplineSeries> | |
27 | #include <QScatterSeries> |
|
27 | #include <QScatterSeries> | |
28 | #include "customtablemodel.h" |
|
28 | #include "customtablemodel.h" | |
29 | #include <QPieSeries> |
|
29 | #include <QPieSeries> | |
30 | #include <QPieSlice> |
|
30 | #include <QPieSlice> | |
31 | #include <QAreaSeries> |
|
31 | #include <QAreaSeries> | |
32 | #include <QBarSeries> |
|
32 | #include <QBarSeries> | |
33 | #include <QBarSet> |
|
33 | #include <QBarSet> | |
34 | #include <QPushButton> |
|
34 | #include <QPushButton> | |
35 | #include <QRadioButton> |
|
35 | #include <QRadioButton> | |
|
36 | #include <QLabel> | |||
36 | #include <QSpinBox> |
|
37 | #include <QSpinBox> | |
37 | #include <QTime> |
|
38 | #include <QTime> | |
38 |
|
39 | |||
39 | TableWidget::TableWidget(QWidget *parent) |
|
40 | TableWidget::TableWidget(QWidget *parent) | |
40 | : QWidget(parent) |
|
41 | : QWidget(parent) | |
41 | { |
|
42 | { | |
42 | setGeometry(100, 100, 1000, 600); |
|
43 | setGeometry(100, 100, 1000, 600); | |
43 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
44 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
44 | // create simple model for storing data |
|
45 | // create simple model for storing data | |
45 | // user's table data model |
|
46 | // user's table data model | |
46 | m_model = new CustomTableModel; |
|
47 | m_model = new CustomTableModel; | |
47 | m_tableView = new QTableView; |
|
48 | m_tableView = new QTableView; | |
48 | m_tableView->setModel(m_model); |
|
49 | m_tableView->setModel(m_model); | |
49 | m_tableView->setMinimumHeight(300); |
|
50 | m_tableView->setMinimumHeight(300); | |
50 | // tableView->setMinimumSize(340, 480); |
|
51 | // tableView->setMinimumSize(340, 480); | |
51 | // tableView->setItemDelegate(new QStyledItemDelegate); |
|
52 | // tableView->setItemDelegate(new QStyledItemDelegate); | |
52 | m_chart = new QChart; |
|
53 | m_chart = new QChart; | |
53 | m_chartView = new QChartView(m_chart); |
|
54 | m_chartView = new QChartView(m_chart); | |
54 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
55 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
55 | m_chartView->setMinimumSize(640, 480); |
|
56 | m_chartView->setMinimumSize(640, 480); | |
56 |
|
57 | |||
57 | // add, remove data buttons |
|
58 | // add, remove data buttons | |
58 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
59 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); | |
59 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
60 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); | |
60 |
|
61 | |||
61 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
62 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); | |
62 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
63 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); | |
63 |
|
64 | |||
64 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
65 | QPushButton* removeRowButton = new QPushButton("Remove row"); | |
65 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
66 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); | |
66 |
|
67 | |||
|
68 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); | |||
|
69 | ||||
67 | // spin box for setting number of affected items (add, remove) |
|
70 | // spin box for setting number of affected items (add, remove) | |
68 | m_linesCountSpinBox = new QSpinBox; |
|
71 | m_linesCountSpinBox = new QSpinBox; | |
69 | m_linesCountSpinBox->setRange(1, 10); |
|
72 | m_linesCountSpinBox->setRange(1, 10); | |
70 | m_linesCountSpinBox->setValue(1); |
|
73 | m_linesCountSpinBox->setValue(1); | |
71 |
|
74 | |||
72 | // buttons layout |
|
75 | // buttons layout | |
73 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
76 | QVBoxLayout* buttonsLayout = new QVBoxLayout; | |
|
77 | buttonsLayout->addWidget(spinBoxLabel); | |||
74 | buttonsLayout->addWidget(m_linesCountSpinBox); |
|
78 | buttonsLayout->addWidget(m_linesCountSpinBox); | |
75 | buttonsLayout->addWidget(addRowAboveButton); |
|
79 | buttonsLayout->addWidget(addRowAboveButton); | |
76 | buttonsLayout->addWidget(addRowBelowButton); |
|
80 | buttonsLayout->addWidget(addRowBelowButton); | |
77 | buttonsLayout->addWidget(removeRowButton); |
|
81 | buttonsLayout->addWidget(removeRowButton); | |
78 | buttonsLayout->addStretch(); |
|
82 | buttonsLayout->addStretch(); | |
79 |
|
83 | |||
80 | // chart type radio buttons |
|
84 | // chart type radio buttons | |
81 | m_lineRadioButton = new QRadioButton("Line"); |
|
85 | m_lineRadioButton = new QRadioButton("Line"); | |
82 | m_splineRadioButton = new QRadioButton("Spline"); |
|
86 | m_splineRadioButton = new QRadioButton("Spline"); | |
83 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
87 | m_scatterRadioButton = new QRadioButton("Scatter"); | |
84 | m_pieRadioButton = new QRadioButton("Pie"); |
|
88 | m_pieRadioButton = new QRadioButton("Pie"); | |
85 | m_areaRadioButton = new QRadioButton("Area"); |
|
89 | m_areaRadioButton = new QRadioButton("Area"); | |
86 | m_barRadioButton = new QRadioButton("Bar"); |
|
90 | m_barRadioButton = new QRadioButton("Bar"); | |
87 |
|
91 | |||
88 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
92 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
89 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
93 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
90 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
94 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
91 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
95 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
92 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
96 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
93 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
97 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
94 | m_lineRadioButton->setChecked(true); |
|
98 | m_lineRadioButton->setChecked(true); | |
95 |
|
99 | |||
96 | // radio buttons layout |
|
100 | // radio buttons layout | |
97 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
101 | QVBoxLayout* radioLayout = new QVBoxLayout; | |
98 | radioLayout->addWidget(m_lineRadioButton); |
|
102 | radioLayout->addWidget(m_lineRadioButton); | |
99 | radioLayout->addWidget(m_splineRadioButton); |
|
103 | radioLayout->addWidget(m_splineRadioButton); | |
100 | radioLayout->addWidget(m_scatterRadioButton); |
|
104 | radioLayout->addWidget(m_scatterRadioButton); | |
101 | radioLayout->addWidget(m_pieRadioButton); |
|
105 | radioLayout->addWidget(m_pieRadioButton); | |
102 | radioLayout->addWidget(m_areaRadioButton); |
|
106 | radioLayout->addWidget(m_areaRadioButton); | |
103 | radioLayout->addWidget(m_barRadioButton); |
|
107 | radioLayout->addWidget(m_barRadioButton); | |
104 | radioLayout->addStretch(); |
|
108 | radioLayout->addStretch(); | |
105 |
|
109 | |||
106 | // create main layout |
|
110 | // create main layout | |
107 | QGridLayout* mainLayout = new QGridLayout; |
|
111 | QGridLayout* mainLayout = new QGridLayout; | |
108 | mainLayout->addLayout(buttonsLayout, 1, 1); |
|
112 | mainLayout->addLayout(buttonsLayout, 1, 1); | |
109 | mainLayout->addLayout(radioLayout, 2, 1); |
|
113 | mainLayout->addLayout(radioLayout, 2, 1); | |
110 | mainLayout->addWidget(m_tableView, 1, 0); |
|
114 | mainLayout->addWidget(m_tableView, 1, 0); | |
111 | mainLayout->addWidget(m_chartView, 2, 0); |
|
115 | mainLayout->addWidget(m_chartView, 2, 0); | |
112 | setLayout(mainLayout); |
|
116 | setLayout(mainLayout); | |
113 | m_lineRadioButton->setFocus(); |
|
117 | m_lineRadioButton->setFocus(); | |
114 | } |
|
118 | } | |
115 |
|
119 | |||
116 | void TableWidget::addRowAbove() |
|
120 | void TableWidget::addRowAbove() | |
117 | { |
|
121 | { | |
118 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
122 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); | |
119 |
|
123 | |||
120 | } |
|
124 | } | |
121 |
|
125 | |||
122 | void TableWidget::addRowBelow() |
|
126 | void TableWidget::addRowBelow() | |
123 | { |
|
127 | { | |
124 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
128 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); | |
125 |
|
129 | |||
126 | } |
|
130 | } | |
127 |
|
131 | |||
128 | void TableWidget::removeRow() |
|
132 | void TableWidget::removeRow() | |
129 | { |
|
133 | { | |
130 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
134 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); | |
131 | } |
|
135 | } | |
132 |
|
136 | |||
133 | void TableWidget::updateChartType() |
|
137 | void TableWidget::updateChartType(bool toggle) | |
134 | { |
|
138 | { | |
|
139 | // this if is needed, so that the function is only called once. | |||
|
140 | // For the radioButton that was enabled. | |||
|
141 | if (toggle) { | |||
135 | m_chart->removeAllSeries(); |
|
142 | m_chart->removeAllSeries(); | |
|
143 | ||||
|
144 | // renable axes of the chart (pie hides them) | |||
|
145 | // x axis | |||
|
146 | QChartAxis *axis = m_chart->axisX(); | |||
|
147 | axis->setAxisVisible(true); | |||
|
148 | axis->setGridLineVisible(true); | |||
|
149 | axis->setLabelsVisible(true); | |||
|
150 | ||||
|
151 | // y axis | |||
|
152 | axis = m_chart->axisY(); | |||
|
153 | axis->setAxisVisible(true); | |||
|
154 | axis->setGridLineVisible(true); | |||
|
155 | axis->setLabelsVisible(true); | |||
|
156 | ||||
136 | m_model->clearMapping(); |
|
157 | m_model->clearMapping(); | |
137 |
|
158 | |||
138 | QString seriesColorHex = "#000000"; |
|
159 | QString seriesColorHex = "#000000"; | |
139 | QPen pen; |
|
160 | QPen pen; | |
140 | pen.setWidth(2); |
|
161 | pen.setWidth(2); | |
141 |
|
162 | |||
142 | if (m_lineRadioButton->isChecked()) |
|
163 | if (m_lineRadioButton->isChecked()) | |
143 | { |
|
164 | { | |
144 | // series 1 |
|
165 | // series 1 | |
145 | m_series = new QLineSeries; |
|
166 | m_series = new QLineSeries; | |
146 | m_series->setModel(m_model); |
|
167 | m_series->setModel(m_model); | |
147 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
168 | m_series->setModelMapping(0,1, Qt::Vertical); | |
148 | m_series->setModelMappingRange(1, 4); |
|
169 | m_series->setModelMappingRange(1, 4); | |
149 | m_chart->addSeries(m_series); |
|
170 | m_chart->addSeries(m_series); | |
150 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
171 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
151 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); |
|
172 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); | |
152 |
|
173 | |||
153 | // series 2 |
|
174 | // series 2 | |
154 | m_series = new QLineSeries; |
|
175 | m_series = new QLineSeries; | |
155 | m_series->setModel(m_model); |
|
176 | m_series->setModel(m_model); | |
156 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
177 | m_series->setModelMapping(2,3, Qt::Vertical); | |
157 | m_chart->addSeries(m_series); |
|
178 | m_chart->addSeries(m_series); | |
158 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
179 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
159 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
180 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
160 |
|
181 | |||
161 | // series 3 |
|
182 | // series 3 | |
162 | m_series = new QLineSeries; |
|
183 | m_series = new QLineSeries; | |
163 | m_series->setModel(m_model); |
|
184 | m_series->setModel(m_model); | |
164 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
185 | m_series->setModelMapping(4,5, Qt::Vertical); | |
165 | m_series->setModelMappingRange(2, 0); |
|
186 | m_series->setModelMappingRange(2, 0); | |
166 | m_chart->addSeries(m_series); |
|
187 | m_chart->addSeries(m_series); | |
167 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
188 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
168 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
189 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
169 | } |
|
190 | } | |
170 | else if (m_splineRadioButton->isChecked()) |
|
191 | else if (m_splineRadioButton->isChecked()) | |
171 | { |
|
192 | { | |
172 | // series 1 |
|
193 | // series 1 | |
173 | m_series = new QSplineSeries; |
|
194 | m_series = new QSplineSeries; | |
174 | m_series->setModel(m_model); |
|
195 | m_series->setModel(m_model); | |
175 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
196 | m_series->setModelMapping(0,1, Qt::Vertical); | |
176 | m_series->setModelMappingRange(1, 4); |
|
197 | m_series->setModelMappingRange(1, 4); | |
177 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
198 | // series->setModelMapping(0,1, Qt::Horizontal); | |
178 | m_chart->addSeries(m_series); |
|
199 | m_chart->addSeries(m_series); | |
179 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
200 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
180 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); |
|
201 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); | |
181 |
|
202 | |||
182 | // series 2 |
|
203 | // series 2 | |
183 | m_series = new QSplineSeries; |
|
204 | m_series = new QSplineSeries; | |
184 | m_series->setModel(m_model); |
|
205 | m_series->setModel(m_model); | |
185 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
206 | m_series->setModelMapping(2,3, Qt::Vertical); | |
186 | m_series->setModelMappingRange(0, 0); |
|
207 | m_series->setModelMappingRange(0, 0); | |
187 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
208 | // series->setModelMapping(2,3, Qt::Horizontal); | |
188 | m_chart->addSeries(m_series); |
|
209 | m_chart->addSeries(m_series); | |
189 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
210 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
190 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
211 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
191 |
|
212 | |||
192 | // series 3 |
|
213 | // series 3 | |
193 | m_series = new QSplineSeries; |
|
214 | m_series = new QSplineSeries; | |
194 | m_series->setModel(m_model); |
|
215 | m_series->setModel(m_model); | |
195 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
216 | m_series->setModelMapping(4,5, Qt::Vertical); | |
196 | m_series->setModelMappingRange(2, 0); |
|
217 | m_series->setModelMappingRange(2, 0); | |
197 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
218 | // series->setModelMapping(4,5, Qt::Horizontal); | |
198 | m_chart->addSeries(m_series); |
|
219 | m_chart->addSeries(m_series); | |
199 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
220 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
200 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
221 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
201 | } |
|
222 | } | |
202 | else if (m_scatterRadioButton->isChecked()) |
|
223 | else if (m_scatterRadioButton->isChecked()) | |
203 | { |
|
224 | { | |
204 | // series 1 |
|
225 | // series 1 | |
205 | m_series = new QScatterSeries; |
|
226 | m_series = new QScatterSeries; | |
206 | m_series->setModel(m_model); |
|
227 | m_series->setModel(m_model); | |
207 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
228 | m_series->setModelMapping(0,1, Qt::Vertical); | |
208 | m_series->setModelMappingRange(2, 0); |
|
229 | m_series->setModelMappingRange(2, 0); | |
209 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
230 | // series->setModelMapping(0,1, Qt::Horizontal); | |
210 | m_chart->addSeries(m_series); |
|
231 | m_chart->addSeries(m_series); | |
211 |
|
232 | |||
212 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
233 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
213 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
234 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); | |
214 |
|
235 | |||
215 | // series 2 |
|
236 | // series 2 | |
216 | m_series = new QScatterSeries; |
|
237 | m_series = new QScatterSeries; | |
217 | m_series->setModel(m_model); |
|
238 | m_series->setModel(m_model); | |
218 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
239 | m_series->setModelMapping(2,3, Qt::Vertical); | |
219 | m_series->setModelMappingRange(1, 6); |
|
240 | m_series->setModelMappingRange(1, 6); | |
220 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
241 | // series->setModelMapping(2,3, Qt::Horizontal); | |
221 | m_chart->addSeries(m_series); |
|
242 | m_chart->addSeries(m_series); | |
222 |
|
243 | |||
223 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
244 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
224 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
245 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); | |
225 |
|
246 | |||
226 | // series 3 |
|
247 | // series 3 | |
227 | m_series = new QScatterSeries; |
|
248 | m_series = new QScatterSeries; | |
228 | m_series->setModel(m_model); |
|
249 | m_series->setModel(m_model); | |
229 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
250 | m_series->setModelMapping(4,5, Qt::Vertical); | |
230 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
251 | // series->setModelMapping(4,5, Qt::Horizontal); | |
231 | m_chart->addSeries(m_series); |
|
252 | m_chart->addSeries(m_series); | |
232 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
253 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
233 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
254 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); | |
234 | } |
|
255 | } | |
235 | else if (m_pieRadioButton->isChecked()) |
|
256 | else if (m_pieRadioButton->isChecked()) | |
236 | { |
|
257 | { | |
237 | // pie 1 |
|
258 | // pie 1 | |
238 | QPieSeries* pieSeries = new QPieSeries; |
|
259 | QPieSeries* pieSeries = new QPieSeries; | |
239 | pieSeries->setModel(m_model); |
|
260 | pieSeries->setModel(m_model); | |
240 | pieSeries->setModelMapping(0,0, Qt::Vertical); |
|
261 | pieSeries->setModelMapping(0,0, Qt::Vertical); | |
241 | pieSeries->setLabelsVisible(true); |
|
262 | pieSeries->setLabelsVisible(true); | |
242 | pieSeries->setPieSize(0.4); |
|
263 | pieSeries->setPieSize(0.4); | |
243 | pieSeries->setPiePosition(0.2, 0.35); |
|
264 | pieSeries->setPiePosition(0.2, 0.35); | |
244 |
|
265 | |||
245 | m_chart->addSeries(pieSeries); |
|
266 | m_chart->addSeries(pieSeries); | |
246 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
267 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
247 | m_model->addMapping(seriesColorHex, QRect(0, 0, 1, 1000)); |
|
268 | m_model->addMapping(seriesColorHex, QRect(0, 0, 1, 1000)); | |
248 |
|
269 | |||
249 | // pie 2 |
|
270 | // pie 2 | |
250 | pieSeries = new QPieSeries; |
|
271 | pieSeries = new QPieSeries; | |
251 | pieSeries->setModel(m_model); |
|
272 | pieSeries->setModel(m_model); | |
252 | pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
273 | pieSeries->setModelMapping(1,1, Qt::Vertical); | |
253 | pieSeries->setLabelsVisible(true); |
|
274 | pieSeries->setLabelsVisible(true); | |
254 | pieSeries->setPieSize(0.4); |
|
275 | pieSeries->setPieSize(0.4); | |
255 | pieSeries->setPiePosition(0.8, 0.35); |
|
276 | pieSeries->setPiePosition(0.8, 0.35); | |
256 | m_chart->addSeries(pieSeries); |
|
277 | m_chart->addSeries(pieSeries); | |
257 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
278 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
258 | m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000)); |
|
279 | m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000)); | |
259 |
|
280 | |||
260 | // pie 3 |
|
281 | // pie 3 | |
261 | pieSeries = new QPieSeries; |
|
282 | pieSeries = new QPieSeries; | |
262 | pieSeries->setModel(m_model); |
|
283 | pieSeries->setModel(m_model); | |
263 | pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
284 | pieSeries->setModelMapping(2,2, Qt::Vertical); | |
264 | pieSeries->setLabelsVisible(true); |
|
285 | pieSeries->setLabelsVisible(true); | |
265 | pieSeries->setPieSize(0.4); |
|
286 | pieSeries->setPieSize(0.4); | |
266 | pieSeries->setPiePosition(0.5, 0.65); |
|
287 | pieSeries->setPiePosition(0.5, 0.65); | |
267 | m_chart->addSeries(pieSeries); |
|
288 | m_chart->addSeries(pieSeries); | |
268 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
289 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
269 | m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
290 | m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | |
270 | } |
|
291 | } | |
271 | else if (m_areaRadioButton->isChecked()) |
|
292 | else if (m_areaRadioButton->isChecked()) | |
272 | { |
|
293 | { | |
273 | QLineSeries* upperLineSeries = new QLineSeries; |
|
294 | QLineSeries* upperLineSeries = new QLineSeries; | |
274 | upperLineSeries->setModel(m_model); |
|
295 | upperLineSeries->setModel(m_model); | |
275 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
296 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | |
276 | upperLineSeries->setModelMappingRange(1, 5); |
|
297 | upperLineSeries->setModelMappingRange(1, 5); | |
277 | QLineSeries* lowerLineSeries = new QLineSeries; |
|
298 | QLineSeries* lowerLineSeries = new QLineSeries; | |
278 | lowerLineSeries->setModel(m_model); |
|
299 | lowerLineSeries->setModel(m_model); | |
279 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
300 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); | |
280 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
301 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | |
281 | m_chart->addSeries(areaSeries); |
|
302 | m_chart->addSeries(areaSeries); | |
282 | seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
303 | seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); | |
283 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
304 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); | |
284 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
305 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
285 | } |
|
306 | } | |
286 | else if (m_barRadioButton->isChecked()) |
|
307 | else if (m_barRadioButton->isChecked()) | |
287 | { |
|
308 | { | |
288 | QBarSeries* barSeries = new QBarSeries(QStringList()); |
|
309 | QBarSeries* barSeries = new QBarSeries(QStringList()); | |
289 | barSeries->setModel(m_model); |
|
310 | barSeries->setModel(m_model); | |
290 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
311 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
291 | barSeries->setToolTipEnabled(true); |
|
312 | barSeries->setToolTipEnabled(true); | |
292 | m_chart->addSeries(barSeries); |
|
313 | m_chart->addSeries(barSeries); | |
293 | for (int i = 0; i < barSeries->barsetCount(); i++) { |
|
314 | for (int i = 0; i < barSeries->barsetCount(); i++) { | |
294 | seriesColorHex = "#" + QString::number(barSeries->barsetAt(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
315 | seriesColorHex = "#" + QString::number(barSeries->barsetAt(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
295 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
316 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); | |
296 | } |
|
317 | } | |
297 | } |
|
318 | } | |
298 |
|
319 | |||
299 |
|
320 | |||
300 | m_chart->axisX()->setRange(0, 500); |
|
321 | m_chart->axisX()->setRange(0, 500); | |
301 | m_chart->axisY()->setRange(0, 120); |
|
322 | m_chart->axisY()->setRange(0, 120); | |
302 |
|
323 | |||
303 | // repaint table view colors |
|
324 | // repaint table view colors | |
304 | m_tableView->repaint(); |
|
325 | m_tableView->repaint(); | |
305 | m_tableView->setFocus(); |
|
326 | m_tableView->setFocus(); | |
306 | } |
|
327 | } | |
|
328 | } | |||
307 |
|
329 | |||
308 | TableWidget::~TableWidget() |
|
330 | TableWidget::~TableWidget() | |
309 | { |
|
331 | { | |
310 |
|
332 | |||
311 | } |
|
333 | } |
@@ -1,66 +1,66 | |||||
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 | #ifndef TABLEWIDGET_H |
|
21 | #ifndef TABLEWIDGET_H | |
22 | #define TABLEWIDGET_H |
|
22 | #define TABLEWIDGET_H | |
23 |
|
23 | |||
24 | #include <QtGui/QWidget> |
|
24 | #include <QtGui/QWidget> | |
25 | #include "qchartview.h" |
|
25 | #include "qchartview.h" | |
26 | #include "qxyseries.h" |
|
26 | #include "qxyseries.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | class CustomTableModel; |
|
30 | class CustomTableModel; | |
31 | class QTableView; |
|
31 | class QTableView; | |
32 | class QRadioButton; |
|
32 | class QRadioButton; | |
33 | class QSpinBox; |
|
33 | class QSpinBox; | |
34 | //class QSeries; |
|
34 | //class QSeries; | |
35 |
|
35 | |||
36 | class TableWidget : public QWidget |
|
36 | class TableWidget : public QWidget | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 |
|
39 | |||
40 | public: |
|
40 | public: | |
41 | TableWidget(QWidget *parent = 0); |
|
41 | TableWidget(QWidget *parent = 0); | |
42 | ~TableWidget(); |
|
42 | ~TableWidget(); | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | public slots: |
|
45 | public slots: | |
46 | void addRowAbove(); |
|
46 | void addRowAbove(); | |
47 | void addRowBelow(); |
|
47 | void addRowBelow(); | |
48 | void removeRow(); |
|
48 | void removeRow(); | |
49 | void updateChartType(); |
|
49 | void updateChartType(bool toggle); | |
50 |
|
50 | |||
51 | private: |
|
51 | private: | |
52 | QChartView* m_chartView; |
|
52 | QChartView* m_chartView; | |
53 | QChart* m_chart; |
|
53 | QChart* m_chart; | |
54 | QXYSeries* m_series; |
|
54 | QXYSeries* m_series; | |
55 | CustomTableModel* m_model; |
|
55 | CustomTableModel* m_model; | |
56 | QTableView* m_tableView; |
|
56 | QTableView* m_tableView; | |
57 | QRadioButton* m_lineRadioButton; |
|
57 | QRadioButton* m_lineRadioButton; | |
58 | QRadioButton* m_splineRadioButton; |
|
58 | QRadioButton* m_splineRadioButton; | |
59 | QRadioButton* m_scatterRadioButton; |
|
59 | QRadioButton* m_scatterRadioButton; | |
60 | QRadioButton* m_pieRadioButton; |
|
60 | QRadioButton* m_pieRadioButton; | |
61 | QRadioButton* m_areaRadioButton; |
|
61 | QRadioButton* m_areaRadioButton; | |
62 | QRadioButton* m_barRadioButton; |
|
62 | QRadioButton* m_barRadioButton; | |
63 | QSpinBox* m_linesCountSpinBox; |
|
63 | QSpinBox* m_linesCountSpinBox; | |
64 | }; |
|
64 | }; | |
65 |
|
65 | |||
66 | #endif // TABLEWIDGET_H |
|
66 | #endif // TABLEWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now