@@ -476,6 +476,7 void QPieSeries::setModelMappingRange(int first, int count) | |||
|
476 | 476 | Q_D(QPieSeries); |
|
477 | 477 | d->m_mapFirst = first; |
|
478 | 478 | d->m_mapCount = count; |
|
479 | d->initializePieFromModel(); | |
|
479 | 480 | } |
|
480 | 481 | |
|
481 | 482 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
@@ -29,9 +29,19 CustomTableModel::CustomTableModel(QObject *parent) : | |||
|
29 | 29 | { |
|
30 | 30 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
31 | 31 | |
|
32 |
m_columnCount = |
|
|
32 | m_columnCount = 3; | |
|
33 | 33 | m_rowCount = 9; |
|
34 | 34 | |
|
35 | m_labels.append("Apples"); | |
|
36 | m_labels.append("Oranges"); | |
|
37 | m_labels.append("Pears"); | |
|
38 | m_labels.append("Peaches"); | |
|
39 | m_labels.append("Coconuts"); | |
|
40 | m_labels.append("Bananas"); | |
|
41 | m_labels.append("Kiwis"); | |
|
42 | m_labels.append("Grapes"); | |
|
43 | m_labels.append("Plums"); | |
|
44 | ||
|
35 | 45 | // m_data |
|
36 | 46 | for (int i = 0; i < m_rowCount; i++) |
|
37 | 47 | { |
@@ -44,7 +54,7 CustomTableModel::CustomTableModel(QObject *parent) : | |||
|
44 | 54 | dataVec->replace(k, qrand()%100); |
|
45 | 55 | } |
|
46 | 56 | m_data.append(dataVec); |
|
47 | m_labels.append(QString("Row: %1").arg((i + 1))); | |
|
57 | // m_labels.append(QString("Row: %1").arg((i + 1))); | |
|
48 | 58 | } |
|
49 | 59 | } |
|
50 | 60 | |
@@ -69,8 +79,12 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, | |||
|
69 | 79 | { |
|
70 | 80 | switch(section) |
|
71 | 81 | { |
|
72 |
|
|
|
73 |
|
|
|
82 | case 0: | |
|
83 | return "Fruit"; | |
|
84 | case 1: | |
|
85 | return "Count"; | |
|
86 | case 2: | |
|
87 | return "Ordered"; | |
|
74 | 88 | default: |
|
75 | 89 | if (section%2 == 0) |
|
76 | 90 | return "x"; |
@@ -88,8 +102,8 QVariant CustomTableModel::data(const QModelIndex & index, int role) const | |||
|
88 | 102 | { |
|
89 | 103 | switch(index.column()) |
|
90 | 104 | { |
|
91 |
|
|
|
92 |
|
|
|
105 | case 0: | |
|
106 | return m_labels[index.row()]; | |
|
93 | 107 | default: |
|
94 | 108 | return m_data[index.row()]->at(index.column()); |
|
95 | 109 | break; |
@@ -99,8 +113,8 QVariant CustomTableModel::data(const QModelIndex & index, int role) const | |||
|
99 | 113 | { |
|
100 | 114 | switch(index.column()) |
|
101 | 115 | { |
|
102 |
|
|
|
103 |
|
|
|
116 | case 0: | |
|
117 | return m_labels[index.row()]; | |
|
104 | 118 | default: |
|
105 | 119 | return m_data[index.row()]->at(index.column()); |
|
106 | 120 | break; |
@@ -125,9 +139,9 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & val | |||
|
125 | 139 | { |
|
126 | 140 | switch(index.column()) |
|
127 | 141 | { |
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
|
142 | case 0: | |
|
143 | m_labels.replace(index.row(), value.toString()); | |
|
144 | break; | |
|
131 | 145 | default: |
|
132 | 146 | m_data[index.row()]->replace(index.column(), value.toDouble()); |
|
133 | 147 | break; |
@@ -37,6 +37,7 | |||
|
37 | 37 | #include <QLabel> |
|
38 | 38 | #include <QSpinBox> |
|
39 | 39 | #include <QTime> |
|
40 | #include <QHeaderView> | |
|
40 | 41 | |
|
41 | 42 | TableWidget::TableWidget(QWidget *parent) |
|
42 | 43 | : QWidget(parent) |
@@ -49,7 +50,10 TableWidget::TableWidget(QWidget *parent) | |||
|
49 | 50 | m_model = new CustomTableModel; |
|
50 | 51 | m_tableView = new QTableView; |
|
51 | 52 | m_tableView->setModel(m_model); |
|
52 | m_tableView->setMinimumHeight(300); | |
|
53 | // m_tableView->setMinimumHeight(300); | |
|
54 | m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |
|
55 | m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |
|
56 | ||
|
53 | 57 | m_chart = new QChart; |
|
54 | 58 | m_chart->legend()->setVisible(true); |
|
55 | 59 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
@@ -86,13 +90,13 TableWidget::TableWidget(QWidget *parent) | |||
|
86 | 90 | |
|
87 | 91 | // buttons layout |
|
88 | 92 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
89 | buttonsLayout->addWidget(spinBoxLabel); | |
|
90 | buttonsLayout->addWidget(m_linesCountSpinBox); | |
|
91 | buttonsLayout->addWidget(addRowAboveButton); | |
|
93 | // buttonsLayout->addWidget(spinBoxLabel); | |
|
94 | // buttonsLayout->addWidget(m_linesCountSpinBox); | |
|
95 | // buttonsLayout->addWidget(addRowAboveButton); | |
|
92 | 96 | buttonsLayout->addWidget(addRowBelowButton); |
|
93 | 97 | buttonsLayout->addWidget(removeRowButton); |
|
94 | buttonsLayout->addWidget(addColumnRightButton); | |
|
95 | buttonsLayout->addWidget(removeColumnButton); | |
|
98 | // buttonsLayout->addWidget(addColumnRightButton); | |
|
99 | // buttonsLayout->addWidget(removeColumnButton); | |
|
96 | 100 | // buttonsLayout->addWidget(specialPieButton); |
|
97 | 101 | buttonsLayout->addStretch(); |
|
98 | 102 | |
@@ -110,7 +114,7 TableWidget::TableWidget(QWidget *parent) | |||
|
110 | 114 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
111 | 115 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
112 | 116 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
113 |
m_ |
|
|
117 | m_pieRadioButton->setChecked(true); | |
|
114 | 118 | |
|
115 | 119 | // radio buttons layout |
|
116 | 120 | QVBoxLayout* radioLayout = new QVBoxLayout; |
@@ -124,10 +128,10 TableWidget::TableWidget(QWidget *parent) | |||
|
124 | 128 | |
|
125 | 129 | // create main layout |
|
126 | 130 | QGridLayout* mainLayout = new QGridLayout; |
|
127 |
mainLayout->addLayout(buttonsLayout, |
|
|
128 | mainLayout->addLayout(radioLayout, 2, 1); | |
|
131 | mainLayout->addLayout(buttonsLayout, 2, 0); | |
|
132 | // mainLayout->addLayout(radioLayout, 2, 1); | |
|
129 | 133 | mainLayout->addWidget(m_tableView, 1, 0); |
|
130 |
mainLayout->addWidget(m_chartView, 2, |
|
|
134 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); | |
|
131 | 135 | setLayout(mainLayout); |
|
132 | 136 | m_lineRadioButton->setFocus(); |
|
133 | 137 | } |
@@ -294,41 +298,42 void TableWidget::updateChartType(bool toggle) | |||
|
294 | 298 | // pie 1 |
|
295 | 299 | QPieSeries* pieSeries = new QPieSeries; |
|
296 | 300 | pieSeries->setModel(m_model); |
|
297 |
pieSeries->setModelMappingRange( |
|
|
298 |
pieSeries->setModelMapping( |
|
|
301 | pieSeries->setModelMappingRange(2, 5); | |
|
302 | pieSeries->setModelMapping(1, 0, Qt::Vertical); | |
|
299 | 303 | pieSeries->setLabelsVisible(true); |
|
300 |
pieSeries->setPieSize(0. |
|
|
301 | pieSeries->setHorizontalPosition(0.2); | |
|
302 | pieSeries->setVerticalPosition(0.3); | |
|
303 | ||
|
304 | m_chart->addSeries(pieSeries); | |
|
305 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
306 | m_model->addMapping(seriesColorHex, QRect(0, 3, 1, 3)); | |
|
304 | pieSeries->setPieSize(0.75); | |
|
305 | // pieSeries->setHorizontalPosition(0.2); | |
|
306 | // pieSeries->setVerticalPosition(0.3); | |
|
307 | 307 | |
|
308 | // pie 2 | |
|
309 | pieSeries = new QPieSeries; | |
|
310 | pieSeries->setModel(m_model); | |
|
311 | pieSeries->setModelMappingRange(2, -1); | |
|
312 | pieSeries->setModelMapping(1,1, Qt::Vertical); | |
|
313 | pieSeries->setLabelsVisible(true); | |
|
314 | pieSeries->setPieSize(0.35); | |
|
315 | pieSeries->setHorizontalPosition(0.8); | |
|
316 | pieSeries->setVerticalPosition(0.3); | |
|
317 | m_chart->addSeries(pieSeries); | |
|
318 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
319 | m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); | |
|
320 | ||
|
321 | // pie 3 | |
|
322 | pieSeries = new QPieSeries; | |
|
323 | pieSeries->setModel(m_model); | |
|
324 | pieSeries->setModelMapping(2,2, Qt::Vertical); | |
|
325 | pieSeries->setLabelsVisible(true); | |
|
326 | pieSeries->setPieSize(0.35); | |
|
327 | pieSeries->setHorizontalPosition(0.5); | |
|
328 | pieSeries->setVerticalPosition(0.75); | |
|
329 | 308 | m_chart->addSeries(pieSeries); |
|
330 | 309 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
331 |
m_model->addMapping(seriesColorHex, QRect(2, |
|
|
310 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5)); | |
|
311 | ||
|
312 | // // pie 2 | |
|
313 | // pieSeries = new QPieSeries; | |
|
314 | // pieSeries->setModel(m_model); | |
|
315 | ||
|
316 | // pieSeries->setModelMapping(1,1, Qt::Vertical); | |
|
317 | // pieSeries->setModelMappingRange(2, -1); | |
|
318 | // pieSeries->setLabelsVisible(true); | |
|
319 | // pieSeries->setPieSize(0.35); | |
|
320 | // pieSeries->setHorizontalPosition(0.8); | |
|
321 | // pieSeries->setVerticalPosition(0.3); | |
|
322 | // m_chart->addSeries(pieSeries); | |
|
323 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
324 | // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); | |
|
325 | ||
|
326 | // // pie 3 | |
|
327 | // pieSeries = new QPieSeries; | |
|
328 | // pieSeries->setModel(m_model); | |
|
329 | // pieSeries->setModelMapping(2,2, Qt::Vertical); | |
|
330 | // pieSeries->setLabelsVisible(true); | |
|
331 | // pieSeries->setPieSize(0.35); | |
|
332 | // pieSeries->setHorizontalPosition(0.5); | |
|
333 | // pieSeries->setVerticalPosition(0.75); | |
|
334 | // m_chart->addSeries(pieSeries); | |
|
335 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
336 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | |
|
332 | 337 | |
|
333 | 338 | // // special pie |
|
334 | 339 | // specialPie = new QPieSeries; |
General Comments 0
You need to be logged in to leave comments.
Login now