@@ -1,66 +1,70 | |||
|
1 | 1 | #ifndef QBARSERIES_P_H |
|
2 | 2 | #define QBARSERIES_P_H |
|
3 | 3 | |
|
4 | 4 | #include "qbarseries.h" |
|
5 | 5 | #include "qabstractseries_p.h" |
|
6 | 6 | #include <QStringList> |
|
7 | 7 | #include <QAbstractSeries> |
|
8 | 8 | |
|
9 | 9 | class QModelIndex; |
|
10 | 10 | |
|
11 | 11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | 12 | |
|
13 | 13 | class QBarModelMapper; |
|
14 | 14 | |
|
15 | 15 | // Container for series |
|
16 | 16 | class QBarSeriesPrivate : public QAbstractSeriesPrivate |
|
17 | 17 | { |
|
18 | 18 | Q_OBJECT |
|
19 | 19 | public: |
|
20 | 20 | QBarSeriesPrivate(QBarSeries *parent); |
|
21 | 21 | void setCategories(QBarCategories categories); |
|
22 | 22 | void setBarMargin(qreal margin); |
|
23 | 23 | qreal barMargin(); |
|
24 | 24 | |
|
25 | 25 | void scaleDomain(Domain& domain); |
|
26 | 26 | Chart* createGraphics(ChartPresenter* presenter); |
|
27 | 27 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
28 | 28 | |
|
29 | 29 | void insertCategory(int index, const QString category); |
|
30 | 30 | void removeCategory(int index); |
|
31 | 31 | |
|
32 | 32 | QBarSet* barsetAt(int index); |
|
33 | 33 | QString categoryName(int category); |
|
34 | 34 | qreal min(); |
|
35 | 35 | qreal max(); |
|
36 | 36 | qreal valueAt(int set, int category); |
|
37 | 37 | qreal percentageAt(int set, int category); |
|
38 | 38 | qreal categorySum(int category); |
|
39 | 39 | qreal absoluteCategorySum(int category); |
|
40 | 40 | qreal maxCategorySum(); |
|
41 | 41 | |
|
42 | 42 | Q_SIGNALS: |
|
43 | 43 | void clicked(QBarSet *barset, QString category); |
|
44 | 44 | void updatedBars(); |
|
45 | 45 | void restructuredBars(); |
|
46 | 46 | void categoriesUpdated(); |
|
47 | 47 | |
|
48 | 48 | private Q_SLOTS: |
|
49 | 49 | // slots for updating bars when data in model changes |
|
50 | 50 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
51 | 51 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
52 | 52 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
53 | 53 | void initializeDataFromModel(); |
|
54 | 54 | void barsetChanged(); |
|
55 | 55 | |
|
56 | 56 | protected: |
|
57 | 57 | QList<QBarSet *> m_barSets; |
|
58 | 58 | QBarCategories m_categories; |
|
59 | qreal m_barMargin; | |
|
60 | int m_mapCategories; | |
|
61 | int m_mapBarBottom; | |
|
62 | int m_mapBarTop; | |
|
59 | 63 | QBarModelMapper *m_mapper; |
|
60 | 64 | private: |
|
61 | 65 | Q_DECLARE_PUBLIC(QBarSeries) |
|
62 | 66 | }; |
|
63 | 67 | |
|
64 | 68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
65 | 69 | |
|
66 | 70 | #endif // QBARSERIESPRIVATE_P_H |
@@ -1,467 +1,468 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "tablewidget.h" |
|
22 | 22 | #include <QGridLayout> |
|
23 | 23 | #include <QTableView> |
|
24 | 24 | #include <QChart> |
|
25 | 25 | #include <QStyledItemDelegate> |
|
26 | 26 | #include <QLineSeries> |
|
27 | 27 | #include <QSplineSeries> |
|
28 | 28 | #include <QScatterSeries> |
|
29 | 29 | #include <QXYModelMapper> |
|
30 | 30 | #include "customtablemodel.h" |
|
31 | 31 | #include <QPieSeries> |
|
32 | 32 | #include <QPieModelMapper> |
|
33 | 33 | #include <QPieSlice> |
|
34 | 34 | #include <QAreaSeries> |
|
35 | 35 | #include <QBarSeries> |
|
36 | #include <QGroupedBarSeries> | |
|
36 | 37 | #include <QBarSet> |
|
37 | 38 | #include <QBarModelMapper> |
|
38 | 39 | #include <QPushButton> |
|
39 | 40 | #include <QRadioButton> |
|
40 | 41 | #include <QLabel> |
|
41 | 42 | #include <QSpinBox> |
|
42 | 43 | #include <QTime> |
|
43 | 44 | #include <QHeaderView> |
|
44 | 45 | |
|
45 | 46 | TableWidget::TableWidget(QWidget *parent) |
|
46 | 47 | : QWidget(parent) |
|
47 | 48 | // specialPie(0) |
|
48 | 49 | { |
|
49 | 50 | setGeometry(1900, 100, 1000, 600); |
|
50 | 51 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
51 | 52 | // create simple model for storing data |
|
52 | 53 | // user's table data model |
|
53 | 54 | m_model = new CustomTableModel; |
|
54 | 55 | m_tableView = new QTableView; |
|
55 | 56 | m_tableView->setModel(m_model); |
|
56 | 57 | // m_tableView->setMinimumHeight(300); |
|
57 | 58 | m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
58 | 59 | m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
59 | 60 | |
|
60 | 61 | m_chart = new QChart; |
|
61 | 62 | m_chart->legend()->setVisible(true); |
|
62 | 63 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
63 | 64 | m_chartView = new QChartView(m_chart); |
|
64 | 65 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
65 | 66 | m_chartView->setMinimumSize(640, 480); |
|
66 | 67 | |
|
67 | 68 | // add, remove data buttons |
|
68 | 69 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
69 | 70 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
70 | 71 | |
|
71 | 72 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
72 | 73 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
73 | 74 | |
|
74 | 75 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
75 | 76 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
76 | 77 | |
|
77 | 78 | QPushButton* addColumnRightButton = new QPushButton("Add column to the right"); |
|
78 | 79 | connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight())); |
|
79 | 80 | |
|
80 | 81 | QPushButton* removeColumnButton = new QPushButton("Remove column"); |
|
81 | 82 | connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn())); |
|
82 | 83 | |
|
83 | 84 | QPushButton* specialPieButton = new QPushButton("Test pie"); |
|
84 | 85 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); |
|
85 | 86 | |
|
86 | 87 | |
|
87 | 88 | // QLabel *spinBoxLabel = new QLabel("Rows affected:"); |
|
88 | 89 | |
|
89 | 90 | // spin box for setting number of affected items (add, remove) |
|
90 | 91 | m_linesCountSpinBox = new QSpinBox; |
|
91 | 92 | m_linesCountSpinBox->setRange(1, 10); |
|
92 | 93 | m_linesCountSpinBox->setValue(1); |
|
93 | 94 | |
|
94 | 95 | // buttons layout |
|
95 | 96 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
96 | 97 | // buttonsLayout->addWidget(spinBoxLabel); |
|
97 | 98 | // buttonsLayout->addWidget(m_linesCountSpinBox); |
|
98 | 99 | // buttonsLayout->addWidget(addRowAboveButton); |
|
99 | 100 | buttonsLayout->addWidget(addRowBelowButton); |
|
100 | 101 | buttonsLayout->addWidget(removeRowButton); |
|
101 | 102 | // buttonsLayout->addWidget(addColumnRightButton); |
|
102 | 103 | // buttonsLayout->addWidget(removeColumnButton); |
|
103 | 104 | buttonsLayout->addWidget(specialPieButton); |
|
104 | 105 | buttonsLayout->addStretch(); |
|
105 | 106 | |
|
106 | 107 | // chart type radio buttons |
|
107 | 108 | m_lineRadioButton = new QRadioButton("Line"); |
|
108 | 109 | m_splineRadioButton = new QRadioButton("Spline"); |
|
109 | 110 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
110 | 111 | m_pieRadioButton = new QRadioButton("Pie"); |
|
111 | 112 | m_areaRadioButton = new QRadioButton("Area"); |
|
112 | 113 | m_barRadioButton = new QRadioButton("Bar"); |
|
113 | 114 | |
|
114 | 115 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
115 | 116 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
116 | 117 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
117 | 118 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
118 | 119 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
119 | 120 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
120 | 121 | m_lineRadioButton->setChecked(true); |
|
121 | 122 | |
|
122 | 123 | // radio buttons layout |
|
123 | 124 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
124 | 125 | radioLayout->addWidget(m_lineRadioButton); |
|
125 | 126 | radioLayout->addWidget(m_splineRadioButton); |
|
126 | 127 | // radioLayout->addWidget(m_scatterRadioButton); |
|
127 | 128 | radioLayout->addWidget(m_pieRadioButton); |
|
128 | 129 | // radioLayout->addWidget(m_areaRadioButton); |
|
129 | 130 | radioLayout->addWidget(m_barRadioButton); |
|
130 | 131 | radioLayout->addStretch(); |
|
131 | 132 | |
|
132 | 133 | // create main layout |
|
133 | 134 | QGridLayout* mainLayout = new QGridLayout; |
|
134 | 135 | mainLayout->addLayout(buttonsLayout, 2, 0); |
|
135 | 136 | mainLayout->addLayout(radioLayout, 3, 0); |
|
136 | 137 | mainLayout->addWidget(m_tableView, 1, 0); |
|
137 | 138 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); |
|
138 | 139 | setLayout(mainLayout); |
|
139 | 140 | m_lineRadioButton->setFocus(); |
|
140 | 141 | } |
|
141 | 142 | |
|
142 | 143 | void TableWidget::addRowAbove() |
|
143 | 144 | { |
|
144 | 145 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
145 | 146 | |
|
146 | 147 | } |
|
147 | 148 | |
|
148 | 149 | void TableWidget::addRowBelow() |
|
149 | 150 | { |
|
150 | 151 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
151 | 152 | |
|
152 | 153 | } |
|
153 | 154 | |
|
154 | 155 | void TableWidget::removeRow() |
|
155 | 156 | { |
|
156 | 157 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
157 | 158 | } |
|
158 | 159 | |
|
159 | 160 | void TableWidget::addColumnRight() |
|
160 | 161 | { |
|
161 | 162 | m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); |
|
162 | 163 | } |
|
163 | 164 | |
|
164 | 165 | void TableWidget::removeColumn() |
|
165 | 166 | { |
|
166 | 167 | m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); |
|
167 | 168 | } |
|
168 | 169 | |
|
169 | 170 | void TableWidget::updateChartType(bool toggle) |
|
170 | 171 | { |
|
171 | 172 | // this if is needed, so that the function is only called once. |
|
172 | 173 | // For the radioButton that was enabled. |
|
173 | 174 | if (toggle) { |
|
174 | 175 | // specialPie = 0; |
|
175 | 176 | m_chart->removeAllSeries(); |
|
176 | 177 | m_chart->axisX()->setNiceNumbersEnabled(false); |
|
177 | 178 | m_chart->axisY()->setNiceNumbersEnabled(false); |
|
178 | 179 | |
|
179 | 180 | // renable axes of the chart (pie hides them) |
|
180 | 181 | // x axis |
|
181 | 182 | QAxis *axis = m_chart->axisX(); |
|
182 | 183 | axis->setAxisVisible(true); |
|
183 | 184 | axis->setGridLineVisible(true); |
|
184 | 185 | axis->setLabelsVisible(true); |
|
185 | 186 | |
|
186 | 187 | // y axis |
|
187 | 188 | axis = m_chart->axisY(); |
|
188 | 189 | axis->setAxisVisible(true); |
|
189 | 190 | axis->setGridLineVisible(true); |
|
190 | 191 | axis->setLabelsVisible(true); |
|
191 | 192 | |
|
192 | 193 | m_model->clearMapping(); |
|
193 | 194 | |
|
194 | 195 | QString seriesColorHex = "#000000"; |
|
195 | 196 | QPen pen; |
|
196 | 197 | pen.setWidth(2); |
|
197 | 198 | |
|
198 | 199 | if (m_lineRadioButton->isChecked()) |
|
199 | 200 | { |
|
200 | 201 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
201 | 202 | |
|
202 | 203 | // series 1 |
|
203 | 204 | m_series = new QLineSeries; |
|
204 | 205 | m_series->setModel(m_model); |
|
205 | 206 | |
|
206 | 207 | QXYModelMapper *mapper = new QXYModelMapper; |
|
207 | 208 | mapper->setMapX(0); |
|
208 | 209 | mapper->setMapY(1); |
|
209 | 210 | mapper->setFirst(3); |
|
210 | 211 | mapper->setCount(4); |
|
211 | 212 | m_series->setModelMapper(mapper); |
|
212 | 213 | // m_series->setModelMapping(0,1, Qt::Vertical); |
|
213 | 214 | // m_series->setModelMappingRange(3, 4); |
|
214 | 215 | m_chart->addSeries(m_series); |
|
215 | 216 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
216 | 217 | m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); |
|
217 | 218 | |
|
218 | 219 | // series 2 |
|
219 | 220 | m_series = new QLineSeries; |
|
220 | 221 | m_series->setModel(m_model); |
|
221 | 222 | |
|
222 | 223 | mapper = new QXYModelMapper; |
|
223 | 224 | mapper->setMapX(3); |
|
224 | 225 | mapper->setMapY(4); |
|
225 | 226 | // mapper->setFirst(3); |
|
226 | 227 | // mapper->setCount(4); |
|
227 | 228 | m_series->setModelMapper(mapper); |
|
228 | 229 | // m_series->setModelMapping(2,3, Qt::Vertical); |
|
229 | 230 | m_chart->addSeries(m_series); |
|
230 | 231 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
231 | 232 | m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); |
|
232 | 233 | |
|
233 | 234 | // series 3 |
|
234 | 235 | m_series = new QLineSeries; |
|
235 | 236 | m_series->setModel(m_model); |
|
236 | 237 | |
|
237 | 238 | mapper = new QXYModelMapper; |
|
238 | 239 | mapper->setMapX(5); |
|
239 | 240 | mapper->setMapY(6); |
|
240 | 241 | mapper->setFirst(2); |
|
241 | 242 | mapper->setCount(-1); |
|
242 | 243 | m_series->setModelMapper(mapper); |
|
243 | 244 | // m_series->setModelMapping(4,5, Qt::Vertical); |
|
244 | 245 | // m_series->setModelMappingRange(2, -1); |
|
245 | 246 | m_chart->addSeries(m_series); |
|
246 | 247 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
247 | 248 | m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); |
|
248 | 249 | } |
|
249 | 250 | else if (m_splineRadioButton->isChecked()) |
|
250 | 251 | { |
|
251 | 252 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
252 | 253 | |
|
253 | 254 | // series 1 |
|
254 | 255 | m_series = new QSplineSeries; |
|
255 | 256 | m_series->setModel(m_model); |
|
256 | 257 | |
|
257 | 258 | QXYModelMapper *mapper = new QXYModelMapper; |
|
258 | 259 | mapper->setMapX(0); |
|
259 | 260 | mapper->setMapY(1); |
|
260 | 261 | mapper->setFirst(0); |
|
261 | 262 | mapper->setCount(-1); |
|
262 | 263 | |
|
263 | 264 | m_series->setModelMapper(mapper); |
|
264 | 265 | |
|
265 | 266 | m_chart->addSeries(m_series); |
|
266 | 267 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
267 | 268 | m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); |
|
268 | 269 | |
|
269 | 270 | // series 2 |
|
270 | 271 | m_series = new QSplineSeries; |
|
271 | 272 | m_series->setModel(m_model); |
|
272 | 273 | |
|
273 | 274 | mapper = new QXYModelMapper; |
|
274 | 275 | mapper->setMapX(2); |
|
275 | 276 | mapper->setMapY(3); |
|
276 | 277 | mapper->setFirst(2); |
|
277 | 278 | mapper->setCount(4); |
|
278 | 279 | |
|
279 | 280 | m_series->setModelMapper(mapper); |
|
280 | 281 | |
|
281 | 282 | m_chart->addSeries(m_series); |
|
282 | 283 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
283 | 284 | m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); |
|
284 | 285 | |
|
285 | 286 | // series 3 |
|
286 | 287 | m_series = new QSplineSeries; |
|
287 | 288 | m_series->setModel(m_model); |
|
288 | 289 | |
|
289 | 290 | mapper = new QXYModelMapper; |
|
290 | 291 | mapper->setMapX(4); |
|
291 | 292 | mapper->setMapY(5); |
|
292 | 293 | mapper->setFirst(2); |
|
293 | 294 | mapper->setCount(-1); |
|
294 | 295 | |
|
295 | 296 | m_series->setModelMapper(mapper); |
|
296 | 297 | |
|
297 | 298 | m_chart->addSeries(m_series); |
|
298 | 299 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
299 | 300 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
300 | 301 | } |
|
301 | 302 | // else if (m_scatterRadioButton->isChecked()) |
|
302 | 303 | // { |
|
303 | 304 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
304 | 305 | |
|
305 | 306 | // // series 1 |
|
306 | 307 | // m_series = new QScatterSeries; |
|
307 | 308 | // m_series->setModel(m_model); |
|
308 | 309 | // m_series->setModelMapping(0,1, Qt::Vertical); |
|
309 | 310 | // // m_series->setModelMappingRange(2, 0); |
|
310 | 311 | // // series->setModelMapping(0,1, Qt::Horizontal); |
|
311 | 312 | // m_chart->addSeries(m_series); |
|
312 | 313 | |
|
313 | 314 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
314 | 315 | // m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
315 | 316 | |
|
316 | 317 | // // series 2 |
|
317 | 318 | // m_series = new QScatterSeries; |
|
318 | 319 | // m_series->setModel(m_model); |
|
319 | 320 | // m_series->setModelMapping(2,3, Qt::Vertical); |
|
320 | 321 | // // m_series->setModelMappingRange(1, 6); |
|
321 | 322 | // // series->setModelMapping(2,3, Qt::Horizontal); |
|
322 | 323 | // m_chart->addSeries(m_series); |
|
323 | 324 | |
|
324 | 325 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
325 | 326 | // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
326 | 327 | |
|
327 | 328 | // // series 3 |
|
328 | 329 | // m_series = new QScatterSeries; |
|
329 | 330 | // m_series->setModel(m_model); |
|
330 | 331 | // m_series->setModelMapping(4,5, Qt::Vertical); |
|
331 | 332 | // // series->setModelMapping(4,5, Qt::Horizontal); |
|
332 | 333 | // m_chart->addSeries(m_series); |
|
333 | 334 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
334 | 335 | // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
335 | 336 | // } |
|
336 | 337 | else if (m_pieRadioButton->isChecked()) |
|
337 | 338 | { |
|
338 | 339 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
339 | 340 | |
|
340 | 341 | // pie 1 |
|
341 | 342 | QPieSeries* pieSeries = new QPieSeries; |
|
342 | 343 | pieSeries->setModel(m_model); |
|
343 | 344 | |
|
344 | 345 | QPieModelMapper *mapper = new QPieModelMapper; |
|
345 | 346 | mapper->setMapValues(1); |
|
346 | 347 | mapper->setMapLabels(1); |
|
347 | 348 | mapper->setFirst(2); |
|
348 | 349 | mapper->setCount(5); |
|
349 | 350 | pieSeries->setModelMapper(mapper); |
|
350 | 351 | |
|
351 | 352 | pieSeries->setLabelsVisible(true); |
|
352 | 353 | pieSeries->setPieSize(0.75); |
|
353 | 354 | // pieSeries->setHorizontalPosition(0.2); |
|
354 | 355 | // pieSeries->setVerticalPosition(0.3); |
|
355 | 356 | |
|
356 | 357 | m_chart->addSeries(pieSeries); |
|
357 | 358 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
358 | 359 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5)); |
|
359 | 360 | |
|
360 | 361 | // // pie 2 |
|
361 | 362 | // pieSeries = new QPieSeries; |
|
362 | 363 | // pieSeries->setModel(m_model); |
|
363 | 364 | |
|
364 | 365 | // pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
365 | 366 | // pieSeries->setModelMappingRange(2, -1); |
|
366 | 367 | // pieSeries->setLabelsVisible(true); |
|
367 | 368 | // pieSeries->setPieSize(0.35); |
|
368 | 369 | // pieSeries->setHorizontalPosition(0.8); |
|
369 | 370 | // pieSeries->setVerticalPosition(0.3); |
|
370 | 371 | // m_chart->addSeries(pieSeries); |
|
371 | 372 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
372 | 373 | // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); |
|
373 | 374 | |
|
374 | 375 | // // pie 3 |
|
375 | 376 | // pieSeries = new QPieSeries; |
|
376 | 377 | // pieSeries->setModel(m_model); |
|
377 | 378 | // pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
378 | 379 | // pieSeries->setLabelsVisible(true); |
|
379 | 380 | // pieSeries->setPieSize(0.35); |
|
380 | 381 | // pieSeries->setHorizontalPosition(0.5); |
|
381 | 382 | // pieSeries->setVerticalPosition(0.75); |
|
382 | 383 | // m_chart->addSeries(pieSeries); |
|
383 | 384 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
384 | 385 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
385 | 386 | |
|
386 | 387 | // // special pie |
|
387 | 388 | // specialPie = new QPieSeries; |
|
388 | 389 | // specialPie->append(17, "1"); |
|
389 | 390 | // specialPie->append(45, "2"); |
|
390 | 391 | // specialPie->append(77, "3"); |
|
391 | 392 | // specialPie->append(37, "4"); |
|
392 | 393 | // specialPie->append(27, "5"); |
|
393 | 394 | // specialPie->append(47, "6"); |
|
394 | 395 | // specialPie->setPieSize(0.35); |
|
395 | 396 | // specialPie->setHorizontalPosition(0.8); |
|
396 | 397 | // specialPie->setVerticalPosition(0.75); |
|
397 | 398 | // specialPie->setLabelsVisible(true); |
|
398 | 399 | // m_chart->addSeries(specialPie); |
|
399 | 400 | } |
|
400 | 401 | // else if (m_areaRadioButton->isChecked()) |
|
401 | 402 | // { |
|
402 | 403 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
403 | 404 | |
|
404 | 405 | // QLineSeries* upperLineSeries = new QLineSeries; |
|
405 | 406 | // upperLineSeries->setModel(m_model); |
|
406 | 407 | // upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
407 | 408 | // // upperLineSeries->setModelMappingRange(1, 5); |
|
408 | 409 | // QLineSeries* lowerLineSeries = new QLineSeries; |
|
409 | 410 | // lowerLineSeries->setModel(m_model); |
|
410 | 411 | // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
411 | 412 | // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
412 | 413 | // m_chart->addSeries(areaSeries); |
|
413 | 414 | // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
414 | 415 | // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
415 | 416 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
416 | 417 | // } |
|
417 | 418 | else if (m_barRadioButton->isChecked()) |
|
418 | 419 | { |
|
419 | 420 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
420 | 421 | |
|
421 | QBarSeries* barSeries = new QBarSeries(); | |
|
422 | QGroupedBarSeries* barSeries = new QGroupedBarSeries(); | |
|
422 | 423 | barSeries->setCategories(QStringList()); |
|
423 | 424 | barSeries->setModel(m_model); |
|
424 | 425 | // barSeries->setModelMappingRange(2, 5); |
|
425 | 426 | // barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
426 | 427 | |
|
427 | 428 | QBarModelMapper *mapper = new QBarModelMapper; |
|
428 | 429 | mapper->setMapCategories(5); |
|
429 | 430 | mapper->setMapBarBottom(2); |
|
430 | 431 | mapper->setMapBarTop(4); |
|
431 | 432 | barSeries->setModelMapper(mapper); |
|
432 | 433 | m_chart->addSeries(barSeries); |
|
433 | 434 | QList<QBarSet*> barsets = barSeries->barSets(); |
|
434 | 435 | for (int i = 0; i < barsets.count(); i++) { |
|
435 | 436 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
436 | 437 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
437 | 438 | } |
|
438 | 439 | } |
|
439 | 440 | |
|
440 | 441 | |
|
441 | 442 | if (!m_barRadioButton->isChecked()) { |
|
442 | 443 | m_chart->axisX()->setRange(0, 500); |
|
443 | 444 | m_chart->axisY()->setRange(0, 220); |
|
444 | 445 | } |
|
445 | 446 | m_chart->legend()->setVisible(true); |
|
446 | 447 | |
|
447 | 448 | // repaint table view colors |
|
448 | 449 | m_tableView->repaint(); |
|
449 | 450 | m_tableView->setFocus(); |
|
450 | 451 | } |
|
451 | 452 | } |
|
452 | 453 | |
|
453 | 454 | void TableWidget::testPie() |
|
454 | 455 | { |
|
455 | 456 | m_series->modelMapper()->setMapX(4); |
|
456 | 457 | // m_tableView->setColumnWidth(10, 250); |
|
457 | 458 | // if (specialPie) { |
|
458 | 459 | // specialPie->remove(specialPie->slices().at(2)); |
|
459 | 460 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); |
|
460 | 461 | // specialPie->append(4, "heloo"); |
|
461 | 462 | // } |
|
462 | 463 | } |
|
463 | 464 | |
|
464 | 465 | TableWidget::~TableWidget() |
|
465 | 466 | { |
|
466 | 467 | |
|
467 | 468 | } |
General Comments 0
You need to be logged in to leave comments.
Login now