@@ -476,6 +476,7 void QPieSeries::setModelMappingRange(int first, int count) | |||||
476 | Q_D(QPieSeries); |
|
476 | Q_D(QPieSeries); | |
477 | d->m_mapFirst = first; |
|
477 | d->m_mapFirst = first; | |
478 | d->m_mapCount = count; |
|
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 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
30 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
31 |
|
31 | |||
32 |
m_columnCount = |
|
32 | m_columnCount = 3; | |
33 | m_rowCount = 9; |
|
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 | // m_data |
|
45 | // m_data | |
36 | for (int i = 0; i < m_rowCount; i++) |
|
46 | for (int i = 0; i < m_rowCount; i++) | |
37 | { |
|
47 | { | |
@@ -44,7 +54,7 CustomTableModel::CustomTableModel(QObject *parent) : | |||||
44 | dataVec->replace(k, qrand()%100); |
|
54 | dataVec->replace(k, qrand()%100); | |
45 | } |
|
55 | } | |
46 | m_data.append(dataVec); |
|
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 | switch(section) |
|
80 | switch(section) | |
71 | { |
|
81 | { | |
72 |
|
|
82 | case 0: | |
73 |
|
|
83 | return "Fruit"; | |
|
84 | case 1: | |||
|
85 | return "Count"; | |||
|
86 | case 2: | |||
|
87 | return "Ordered"; | |||
74 | default: |
|
88 | default: | |
75 | if (section%2 == 0) |
|
89 | if (section%2 == 0) | |
76 | return "x"; |
|
90 | return "x"; | |
@@ -88,8 +102,8 QVariant CustomTableModel::data(const QModelIndex & index, int role) const | |||||
88 | { |
|
102 | { | |
89 | switch(index.column()) |
|
103 | switch(index.column()) | |
90 | { |
|
104 | { | |
91 |
|
|
105 | case 0: | |
92 |
|
|
106 | return m_labels[index.row()]; | |
93 | default: |
|
107 | default: | |
94 | return m_data[index.row()]->at(index.column()); |
|
108 | return m_data[index.row()]->at(index.column()); | |
95 | break; |
|
109 | break; | |
@@ -99,8 +113,8 QVariant CustomTableModel::data(const QModelIndex & index, int role) const | |||||
99 | { |
|
113 | { | |
100 | switch(index.column()) |
|
114 | switch(index.column()) | |
101 | { |
|
115 | { | |
102 |
|
|
116 | case 0: | |
103 |
|
|
117 | return m_labels[index.row()]; | |
104 | default: |
|
118 | default: | |
105 | return m_data[index.row()]->at(index.column()); |
|
119 | return m_data[index.row()]->at(index.column()); | |
106 | break; |
|
120 | break; | |
@@ -125,9 +139,9 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & val | |||||
125 | { |
|
139 | { | |
126 | switch(index.column()) |
|
140 | switch(index.column()) | |
127 | { |
|
141 | { | |
128 |
|
|
142 | case 0: | |
129 |
|
|
143 | m_labels.replace(index.row(), value.toString()); | |
130 |
|
|
144 | break; | |
131 | default: |
|
145 | default: | |
132 | m_data[index.row()]->replace(index.column(), value.toDouble()); |
|
146 | m_data[index.row()]->replace(index.column(), value.toDouble()); | |
133 | break; |
|
147 | break; |
@@ -37,6 +37,7 | |||||
37 | #include <QLabel> |
|
37 | #include <QLabel> | |
38 | #include <QSpinBox> |
|
38 | #include <QSpinBox> | |
39 | #include <QTime> |
|
39 | #include <QTime> | |
|
40 | #include <QHeaderView> | |||
40 |
|
41 | |||
41 | TableWidget::TableWidget(QWidget *parent) |
|
42 | TableWidget::TableWidget(QWidget *parent) | |
42 | : QWidget(parent) |
|
43 | : QWidget(parent) | |
@@ -49,7 +50,10 TableWidget::TableWidget(QWidget *parent) | |||||
49 | m_model = new CustomTableModel; |
|
50 | m_model = new CustomTableModel; | |
50 | m_tableView = new QTableView; |
|
51 | m_tableView = new QTableView; | |
51 | m_tableView->setModel(m_model); |
|
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 | m_chart = new QChart; |
|
57 | m_chart = new QChart; | |
54 | m_chart->legend()->setVisible(true); |
|
58 | m_chart->legend()->setVisible(true); | |
55 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
59 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
@@ -86,13 +90,13 TableWidget::TableWidget(QWidget *parent) | |||||
86 |
|
90 | |||
87 | // buttons layout |
|
91 | // buttons layout | |
88 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
92 | QVBoxLayout* buttonsLayout = new QVBoxLayout; | |
89 | buttonsLayout->addWidget(spinBoxLabel); |
|
93 | // buttonsLayout->addWidget(spinBoxLabel); | |
90 | buttonsLayout->addWidget(m_linesCountSpinBox); |
|
94 | // buttonsLayout->addWidget(m_linesCountSpinBox); | |
91 | buttonsLayout->addWidget(addRowAboveButton); |
|
95 | // buttonsLayout->addWidget(addRowAboveButton); | |
92 | buttonsLayout->addWidget(addRowBelowButton); |
|
96 | buttonsLayout->addWidget(addRowBelowButton); | |
93 | buttonsLayout->addWidget(removeRowButton); |
|
97 | buttonsLayout->addWidget(removeRowButton); | |
94 | buttonsLayout->addWidget(addColumnRightButton); |
|
98 | // buttonsLayout->addWidget(addColumnRightButton); | |
95 | buttonsLayout->addWidget(removeColumnButton); |
|
99 | // buttonsLayout->addWidget(removeColumnButton); | |
96 | // buttonsLayout->addWidget(specialPieButton); |
|
100 | // buttonsLayout->addWidget(specialPieButton); | |
97 | buttonsLayout->addStretch(); |
|
101 | buttonsLayout->addStretch(); | |
98 |
|
102 | |||
@@ -110,7 +114,7 TableWidget::TableWidget(QWidget *parent) | |||||
110 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
114 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
111 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
115 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
112 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
116 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
113 |
m_ |
|
117 | m_pieRadioButton->setChecked(true); | |
114 |
|
118 | |||
115 | // radio buttons layout |
|
119 | // radio buttons layout | |
116 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
120 | QVBoxLayout* radioLayout = new QVBoxLayout; | |
@@ -124,10 +128,10 TableWidget::TableWidget(QWidget *parent) | |||||
124 |
|
128 | |||
125 | // create main layout |
|
129 | // create main layout | |
126 | QGridLayout* mainLayout = new QGridLayout; |
|
130 | QGridLayout* mainLayout = new QGridLayout; | |
127 |
mainLayout->addLayout(buttonsLayout, |
|
131 | mainLayout->addLayout(buttonsLayout, 2, 0); | |
128 | mainLayout->addLayout(radioLayout, 2, 1); |
|
132 | // mainLayout->addLayout(radioLayout, 2, 1); | |
129 | mainLayout->addWidget(m_tableView, 1, 0); |
|
133 | mainLayout->addWidget(m_tableView, 1, 0); | |
130 |
mainLayout->addWidget(m_chartView, 2, |
|
134 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); | |
131 | setLayout(mainLayout); |
|
135 | setLayout(mainLayout); | |
132 | m_lineRadioButton->setFocus(); |
|
136 | m_lineRadioButton->setFocus(); | |
133 | } |
|
137 | } | |
@@ -294,41 +298,42 void TableWidget::updateChartType(bool toggle) | |||||
294 | // pie 1 |
|
298 | // pie 1 | |
295 | QPieSeries* pieSeries = new QPieSeries; |
|
299 | QPieSeries* pieSeries = new QPieSeries; | |
296 | pieSeries->setModel(m_model); |
|
300 | pieSeries->setModel(m_model); | |
297 |
pieSeries->setModelMappingRange( |
|
301 | pieSeries->setModelMappingRange(2, 5); | |
298 |
pieSeries->setModelMapping( |
|
302 | pieSeries->setModelMapping(1, 0, Qt::Vertical); | |
299 | pieSeries->setLabelsVisible(true); |
|
303 | pieSeries->setLabelsVisible(true); | |
300 |
pieSeries->setPieSize(0. |
|
304 | pieSeries->setPieSize(0.75); | |
301 | pieSeries->setHorizontalPosition(0.2); |
|
305 | // pieSeries->setHorizontalPosition(0.2); | |
302 | pieSeries->setVerticalPosition(0.3); |
|
306 | // 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)); |
|
|||
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 | m_chart->addSeries(pieSeries); |
|
308 | m_chart->addSeries(pieSeries); | |
330 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
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 | // // special pie |
|
338 | // // special pie | |
334 | // specialPie = new QPieSeries; |
|
339 | // specialPie = new QPieSeries; |
General Comments 0
You need to be logged in to leave comments.
Login now