@@ -0,0 +1,8 | |||||
|
1 | !include( ../auto.pri ) { | |||
|
2 | error( "Couldn't find the auto.pri file!" ) | |||
|
3 | } | |||
|
4 | ||||
|
5 | SOURCES += \ | |||
|
6 | tst_qpiemodelmapper.cpp | |||
|
7 | ||||
|
8 | !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" |
@@ -0,0 +1,241 | |||||
|
1 | #include <QtCore/QString> | |||
|
2 | #include <QtTest/QtTest> | |||
|
3 | ||||
|
4 | #include <qchart.h> | |||
|
5 | #include <qchartview.h> | |||
|
6 | #include <qpieseries.h> | |||
|
7 | #include <qvpiemodelmapper.h> | |||
|
8 | #include <qhpiemodelmapper.h> | |||
|
9 | #include <QStandardItemModel> | |||
|
10 | ||||
|
11 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
12 | ||||
|
13 | class tst_piemodelmapper : public QObject | |||
|
14 | { | |||
|
15 | Q_OBJECT | |||
|
16 | ||||
|
17 | public: | |||
|
18 | tst_piemodelmapper(); | |||
|
19 | ||||
|
20 | private Q_SLOTS: | |||
|
21 | void initTestCase(); | |||
|
22 | void cleanupTestCase(); | |||
|
23 | void init(); | |||
|
24 | void cleanup(); | |||
|
25 | void verticalMapper_data(); | |||
|
26 | void verticalMapper(); | |||
|
27 | void verticalMapperCustomMapping_data(); | |||
|
28 | void verticalMapperCustomMapping(); | |||
|
29 | void horizontalMapper_data(); | |||
|
30 | void horizontalMapper(); | |||
|
31 | void horizontalMapperCustomMapping_data(); | |||
|
32 | void horizontalMapperCustomMapping(); | |||
|
33 | ||||
|
34 | ||||
|
35 | private: | |||
|
36 | QStandardItemModel *m_model; | |||
|
37 | int m_modelRowCount; | |||
|
38 | int m_modelColumnCount; | |||
|
39 | ||||
|
40 | QPieSeries *m_series; | |||
|
41 | QChart *m_chart; | |||
|
42 | }; | |||
|
43 | ||||
|
44 | tst_piemodelmapper::tst_piemodelmapper(): | |||
|
45 | m_model(0), | |||
|
46 | m_modelRowCount(10), | |||
|
47 | m_modelColumnCount(8) | |||
|
48 | { | |||
|
49 | } | |||
|
50 | ||||
|
51 | void tst_piemodelmapper::init() | |||
|
52 | { | |||
|
53 | m_series = new QPieSeries; | |||
|
54 | m_chart->addSeries(m_series); | |||
|
55 | } | |||
|
56 | ||||
|
57 | void tst_piemodelmapper::cleanup() | |||
|
58 | { | |||
|
59 | m_chart->removeSeries(m_series); | |||
|
60 | delete m_series; | |||
|
61 | m_series = 0; | |||
|
62 | } | |||
|
63 | ||||
|
64 | void tst_piemodelmapper::initTestCase() | |||
|
65 | { | |||
|
66 | m_chart = new QChart; | |||
|
67 | QChartView *chartView = new QChartView(m_chart); | |||
|
68 | chartView->show(); | |||
|
69 | ||||
|
70 | m_model = new QStandardItemModel(this); | |||
|
71 | for (int row = 0; row < m_modelRowCount; ++row) { | |||
|
72 | for (int column = 0; column < m_modelColumnCount; column++) { | |||
|
73 | QStandardItem *item = new QStandardItem(row * column); | |||
|
74 | m_model->setItem(row, column, item); | |||
|
75 | } | |||
|
76 | } | |||
|
77 | } | |||
|
78 | ||||
|
79 | void tst_piemodelmapper::cleanupTestCase() | |||
|
80 | { | |||
|
81 | m_model->clear(); | |||
|
82 | } | |||
|
83 | ||||
|
84 | void tst_piemodelmapper::verticalMapper_data() | |||
|
85 | { | |||
|
86 | QTest::addColumn<int>("valuesColumn"); | |||
|
87 | QTest::addColumn<int>("labelsColumn"); | |||
|
88 | QTest::addColumn<int>("expectedCount"); | |||
|
89 | QTest::newRow("different values and labels columns") << 0 << 1 << m_modelRowCount; | |||
|
90 | QTest::newRow("same values and labels columns") << 1 << 1 << m_modelRowCount; | |||
|
91 | QTest::newRow("invalid values column and correct labels column") << -3 << 1 << 0; | |||
|
92 | QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << 1 << 0; | |||
|
93 | QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << -1 << 0; | |||
|
94 | } | |||
|
95 | ||||
|
96 | void tst_piemodelmapper::verticalMapper() | |||
|
97 | { | |||
|
98 | QFETCH(int, valuesColumn); | |||
|
99 | QFETCH(int, labelsColumn); | |||
|
100 | QFETCH(int, expectedCount); | |||
|
101 | ||||
|
102 | QVPieModelMapper *mapper = new QVPieModelMapper; | |||
|
103 | mapper->setValuesColumn(valuesColumn); | |||
|
104 | mapper->setLabelsColumn(labelsColumn); | |||
|
105 | mapper->setModel(m_model); | |||
|
106 | mapper->setSeries(m_series); | |||
|
107 | ||||
|
108 | QCOMPARE(m_series->count(), expectedCount); | |||
|
109 | QCOMPARE(mapper->valuesColumn(), qMax(-1, valuesColumn)); | |||
|
110 | QCOMPARE(mapper->labelsColumn(), qMax(-1, labelsColumn)); | |||
|
111 | ||||
|
112 | delete mapper; | |||
|
113 | mapper = 0; | |||
|
114 | } | |||
|
115 | ||||
|
116 | void tst_piemodelmapper::verticalMapperCustomMapping_data() | |||
|
117 | { | |||
|
118 | QTest::addColumn<int>("first"); | |||
|
119 | QTest::addColumn<int>("countLimit"); | |||
|
120 | QTest::addColumn<int>("expectedCount"); | |||
|
121 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount; | |||
|
122 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3; | |||
|
123 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount); | |||
|
124 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3); | |||
|
125 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0; | |||
|
126 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0; | |||
|
127 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << m_modelRowCount; | |||
|
128 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount; | |||
|
129 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount; | |||
|
130 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount; | |||
|
131 | ||||
|
132 | } | |||
|
133 | ||||
|
134 | void tst_piemodelmapper::verticalMapperCustomMapping() | |||
|
135 | { | |||
|
136 | QFETCH(int, first); | |||
|
137 | QFETCH(int, countLimit); | |||
|
138 | QFETCH(int, expectedCount); | |||
|
139 | ||||
|
140 | QCOMPARE(m_series->count(), 0); | |||
|
141 | ||||
|
142 | QVPieModelMapper *mapper = new QVPieModelMapper; | |||
|
143 | mapper->setValuesColumn(0); | |||
|
144 | mapper->setLabelsColumn(1); | |||
|
145 | mapper->setModel(m_model); | |||
|
146 | mapper->setSeries(m_series); | |||
|
147 | mapper->setFirst(first); | |||
|
148 | mapper->setCount(countLimit); | |||
|
149 | ||||
|
150 | QCOMPARE(m_series->count(), expectedCount); | |||
|
151 | ||||
|
152 | // change values column mappings to invalid | |||
|
153 | mapper->setValuesColumn(-1); | |||
|
154 | mapper->setLabelsColumn(1); | |||
|
155 | ||||
|
156 | QCOMPARE(m_series->count(), 0); | |||
|
157 | ||||
|
158 | delete mapper; | |||
|
159 | mapper = 0; | |||
|
160 | } | |||
|
161 | ||||
|
162 | void tst_piemodelmapper::horizontalMapper_data() | |||
|
163 | { | |||
|
164 | QTest::addColumn<int>("valuesRow"); | |||
|
165 | QTest::addColumn<int>("labelsRow"); | |||
|
166 | QTest::addColumn<int>("expectedCount"); | |||
|
167 | QTest::newRow("different values and labels rows") << 0 << 1 << m_modelColumnCount; | |||
|
168 | QTest::newRow("same values and labels rows") << 1 << 1 << m_modelColumnCount; | |||
|
169 | QTest::newRow("invalid values row and correct labels row") << -3 << 1 << 0; | |||
|
170 | QTest::newRow("values row beyond the size of model and correct labels row") << m_modelRowCount << 1 << 0; | |||
|
171 | QTest::newRow("values row beyond the size of model and invalid labels row") << m_modelRowCount << -1 << 0; | |||
|
172 | } | |||
|
173 | ||||
|
174 | void tst_piemodelmapper::horizontalMapper() | |||
|
175 | { | |||
|
176 | QFETCH(int, valuesRow); | |||
|
177 | QFETCH(int, labelsRow); | |||
|
178 | QFETCH(int, expectedCount); | |||
|
179 | ||||
|
180 | QHPieModelMapper *mapper = new QHPieModelMapper; | |||
|
181 | mapper->setValuesRow(valuesRow); | |||
|
182 | mapper->setLabelsRow(labelsRow); | |||
|
183 | mapper->setModel(m_model); | |||
|
184 | mapper->setSeries(m_series); | |||
|
185 | ||||
|
186 | QCOMPARE(m_series->count(), expectedCount); | |||
|
187 | QCOMPARE(mapper->valuesRow(), qMax(-1, valuesRow)); | |||
|
188 | QCOMPARE(mapper->labelsRow(), qMax(-1, labelsRow)); | |||
|
189 | ||||
|
190 | delete mapper; | |||
|
191 | mapper = 0; | |||
|
192 | } | |||
|
193 | ||||
|
194 | void tst_piemodelmapper::horizontalMapperCustomMapping_data() | |||
|
195 | { | |||
|
196 | QTest::addColumn<int>("first"); | |||
|
197 | QTest::addColumn<int>("countLimit"); | |||
|
198 | QTest::addColumn<int>("expectedCount"); | |||
|
199 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount; | |||
|
200 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3; | |||
|
201 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount); | |||
|
202 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3); | |||
|
203 | QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0; | |||
|
204 | QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0; | |||
|
205 | QTest::newRow("first: 0, count: +3 greater than the number of columns in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << m_modelColumnCount; | |||
|
206 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount; | |||
|
207 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount; | |||
|
208 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount; | |||
|
209 | } | |||
|
210 | ||||
|
211 | void tst_piemodelmapper::horizontalMapperCustomMapping() | |||
|
212 | { | |||
|
213 | QFETCH(int, first); | |||
|
214 | QFETCH(int, countLimit); | |||
|
215 | QFETCH(int, expectedCount); | |||
|
216 | ||||
|
217 | QCOMPARE(m_series->count(), 0); | |||
|
218 | ||||
|
219 | QHPieModelMapper *mapper = new QHPieModelMapper; | |||
|
220 | mapper->setValuesRow(0); | |||
|
221 | mapper->setLabelsRow(1); | |||
|
222 | mapper->setModel(m_model); | |||
|
223 | mapper->setSeries(m_series); | |||
|
224 | mapper->setFirst(first); | |||
|
225 | mapper->setCount(countLimit); | |||
|
226 | ||||
|
227 | QCOMPARE(m_series->count(), expectedCount); | |||
|
228 | ||||
|
229 | // change values column mappings to invalid | |||
|
230 | mapper->setValuesRow(-1); | |||
|
231 | mapper->setLabelsRow(1); | |||
|
232 | ||||
|
233 | QCOMPARE(m_series->count(), 0); | |||
|
234 | ||||
|
235 | delete mapper; | |||
|
236 | mapper = 0; | |||
|
237 | } | |||
|
238 | ||||
|
239 | QTEST_MAIN(tst_piemodelmapper) | |||
|
240 | ||||
|
241 | #include "tst_qpiemodelmapper.moc" |
@@ -1,475 +1,465 | |||||
1 | #include "qpiemodelmapper_p.h" |
|
1 | #include "qpiemodelmapper_p.h" | |
2 | #include "qpiemodelmapper.h" |
|
2 | #include "qpiemodelmapper.h" | |
3 | #include "qpieseries.h" |
|
3 | #include "qpieseries.h" | |
4 | #include "qpieslice.h" |
|
4 | #include "qpieslice.h" | |
5 | #include <QAbstractItemModel> |
|
5 | #include <QAbstractItemModel> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | QPieModelMapper::QPieModelMapper(QObject *parent) : |
|
9 | QPieModelMapper::QPieModelMapper(QObject *parent) : | |
10 | QObject(parent), |
|
10 | QObject(parent), | |
11 | d_ptr(new QPieModelMapperPrivate(this)) |
|
11 | d_ptr(new QPieModelMapperPrivate(this)) | |
12 | { |
|
12 | { | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | QAbstractItemModel* QPieModelMapper::model() const |
|
15 | QAbstractItemModel* QPieModelMapper::model() const | |
16 | { |
|
16 | { | |
17 | Q_D(const QPieModelMapper); |
|
17 | Q_D(const QPieModelMapper); | |
18 | return d->m_model; |
|
18 | return d->m_model; | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | void QPieModelMapper::setModel(QAbstractItemModel *model) |
|
21 | void QPieModelMapper::setModel(QAbstractItemModel *model) | |
22 | { |
|
22 | { | |
23 | if (model == 0) |
|
23 | if (model == 0) | |
24 | return; |
|
24 | return; | |
25 |
|
25 | |||
26 | Q_D(QPieModelMapper); |
|
26 | Q_D(QPieModelMapper); | |
27 | if (d->m_model) { |
|
27 | if (d->m_model) { | |
28 | disconnect(d->m_model, 0, d, 0); |
|
28 | disconnect(d->m_model, 0, d, 0); | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | d->m_model = model; |
|
31 | d->m_model = model; | |
32 | d->initializePieFromModel(); |
|
32 | d->initializePieFromModel(); | |
33 | // connect signals from the model |
|
33 | // connect signals from the model | |
34 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
34 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
35 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
35 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
36 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
36 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
37 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
37 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
38 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
38 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QPieSeries* QPieModelMapper::series() const |
|
41 | QPieSeries* QPieModelMapper::series() const | |
42 | { |
|
42 | { | |
43 | Q_D(const QPieModelMapper); |
|
43 | Q_D(const QPieModelMapper); | |
44 | return d->m_series; |
|
44 | return d->m_series; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void QPieModelMapper::setSeries(QPieSeries *series) |
|
47 | void QPieModelMapper::setSeries(QPieSeries *series) | |
48 | { |
|
48 | { | |
49 | if (series == 0) |
|
49 | if (series == 0) | |
50 | return; |
|
50 | return; | |
51 |
|
51 | |||
52 | Q_D(QPieModelMapper); |
|
52 | Q_D(QPieModelMapper); | |
53 | if (d->m_series) { |
|
53 | if (d->m_series) { | |
54 | disconnect(d->m_series, 0, d, 0); |
|
54 | disconnect(d->m_series, 0, d, 0); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | d->m_series = series; |
|
57 | d->m_series = series; | |
58 | d->initializePieFromModel(); |
|
58 | d->initializePieFromModel(); | |
59 | // connect the signals from the series |
|
59 | // connect the signals from the series | |
60 | connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>))); |
|
60 | connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>))); | |
61 | connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>))); |
|
61 | connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>))); | |
62 | // connect(d->m_model, SIGNAL(), d, SLOT()); |
|
62 | // connect(d->m_model, SIGNAL(), d, SLOT()); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | int QPieModelMapper::first() const |
|
65 | int QPieModelMapper::first() const | |
66 | { |
|
66 | { | |
67 | Q_D(const QPieModelMapper); |
|
67 | Q_D(const QPieModelMapper); | |
68 | return d->m_first; |
|
68 | return d->m_first; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void QPieModelMapper::setFirst(int first) |
|
71 | void QPieModelMapper::setFirst(int first) | |
72 | { |
|
72 | { | |
73 | Q_D(QPieModelMapper); |
|
73 | Q_D(QPieModelMapper); | |
74 | d->m_first = qMax(first, 0); |
|
74 | d->m_first = qMax(first, 0); | |
75 | d->initializePieFromModel(); |
|
75 | d->initializePieFromModel(); | |
76 | // emit updated(); |
|
|||
77 | } |
|
76 | } | |
78 |
|
77 | |||
79 | int QPieModelMapper::count() const |
|
78 | int QPieModelMapper::count() const | |
80 | { |
|
79 | { | |
81 | Q_D(const QPieModelMapper); |
|
80 | Q_D(const QPieModelMapper); | |
82 | return d->m_count; |
|
81 | return d->m_count; | |
83 | } |
|
82 | } | |
84 |
|
83 | |||
85 | void QPieModelMapper::setCount(int count) |
|
84 | void QPieModelMapper::setCount(int count) | |
86 | { |
|
85 | { | |
87 | Q_D(QPieModelMapper); |
|
86 | Q_D(QPieModelMapper); | |
88 | d->m_count = qMax(count, -1); |
|
87 | d->m_count = qMax(count, -1); | |
89 | d->initializePieFromModel(); |
|
88 | d->initializePieFromModel(); | |
90 | // emit updated(); |
|
|||
91 | } |
|
89 | } | |
92 |
|
90 | |||
93 | Qt::Orientation QPieModelMapper::orientation() const |
|
91 | Qt::Orientation QPieModelMapper::orientation() const | |
94 | { |
|
92 | { | |
95 | Q_D(const QPieModelMapper); |
|
93 | Q_D(const QPieModelMapper); | |
96 | return d->m_orientation; |
|
94 | return d->m_orientation; | |
97 | } |
|
95 | } | |
98 |
|
96 | |||
99 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) |
|
97 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) | |
100 | { |
|
98 | { | |
101 | Q_D(QPieModelMapper); |
|
99 | Q_D(QPieModelMapper); | |
102 | d->m_orientation = orientation; |
|
100 | d->m_orientation = orientation; | |
103 | d->initializePieFromModel(); |
|
101 | d->initializePieFromModel(); | |
104 | // emit updated(); |
|
|||
105 | } |
|
102 | } | |
106 |
|
103 | |||
107 | int QPieModelMapper::valuesIndex() const |
|
104 | int QPieModelMapper::valuesIndex() const | |
108 | { |
|
105 | { | |
109 | Q_D(const QPieModelMapper); |
|
106 | Q_D(const QPieModelMapper); | |
110 | return d->m_valuesIndex; |
|
107 | return d->m_valuesIndex; | |
111 | } |
|
108 | } | |
112 |
|
109 | |||
113 |
void QPieModelMapper::setValuesIndex(int |
|
110 | void QPieModelMapper::setValuesIndex(int valuesIndex) | |
114 | { |
|
111 | { | |
115 | Q_D(QPieModelMapper); |
|
112 | Q_D(QPieModelMapper); | |
116 |
d->m_valuesIndex = |
|
113 | d->m_valuesIndex = qMax(-1, valuesIndex); | |
117 | d->initializePieFromModel(); |
|
114 | d->initializePieFromModel(); | |
118 | // emit updated(); |
|
|||
119 | } |
|
115 | } | |
120 |
|
116 | |||
121 | int QPieModelMapper::labelsIndex() const |
|
117 | int QPieModelMapper::labelsIndex() const | |
122 | { |
|
118 | { | |
123 | Q_D(const QPieModelMapper); |
|
119 | Q_D(const QPieModelMapper); | |
124 | return d->m_labelsIndex; |
|
120 | return d->m_labelsIndex; | |
125 | } |
|
121 | } | |
126 |
|
122 | |||
127 |
void QPieModelMapper::setLabelsIndex(int |
|
123 | void QPieModelMapper::setLabelsIndex(int labelsIndex) | |
128 | { |
|
124 | { | |
129 | Q_D(QPieModelMapper); |
|
125 | Q_D(QPieModelMapper); | |
130 |
d->m_labelsIndex = |
|
126 | d->m_labelsIndex = qMax(-1, labelsIndex); | |
131 | d->initializePieFromModel(); |
|
127 | d->initializePieFromModel(); | |
132 | // emit updated(); |
|
|||
133 | } |
|
128 | } | |
134 |
|
129 | |||
135 | void QPieModelMapper::reset() |
|
130 | void QPieModelMapper::reset() | |
136 | { |
|
131 | { | |
137 | Q_D(QPieModelMapper); |
|
132 | Q_D(QPieModelMapper); | |
138 | d->m_first = 0; |
|
133 | d->m_first = 0; | |
139 | d->m_count = -1; |
|
134 | d->m_count = -1; | |
140 | d->m_orientation = Qt::Vertical; |
|
135 | d->m_orientation = Qt::Vertical; | |
141 | d->m_valuesIndex = -1; |
|
136 | d->m_valuesIndex = -1; | |
142 | d->m_labelsIndex = -1; |
|
137 | d->m_labelsIndex = -1; | |
143 | // emit updated(); |
|
|||
144 | } |
|
138 | } | |
145 |
|
139 | |||
146 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
140 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
147 |
|
141 | |||
148 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : |
|
142 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : | |
149 | q_ptr(q) |
|
143 | q_ptr(q) | |
150 | { |
|
144 | { | |
151 | m_series = 0; |
|
145 | m_series = 0; | |
152 | m_model = 0; |
|
146 | m_model = 0; | |
153 | m_first = 0; |
|
147 | m_first = 0; | |
154 | m_count = -1; |
|
148 | m_count = -1; | |
155 | m_orientation = Qt::Vertical; |
|
149 | m_orientation = Qt::Vertical; | |
156 | m_valuesIndex = -1; |
|
150 | m_valuesIndex = -1; | |
157 | m_labelsIndex = -1; |
|
151 | m_labelsIndex = -1; | |
158 | m_seriesSignalsBlock = false; |
|
152 | m_seriesSignalsBlock = false; | |
159 | m_modelSignalsBlock = false; |
|
153 | m_modelSignalsBlock = false; | |
160 | } |
|
154 | } | |
161 |
|
155 | |||
162 | void QPieModelMapperPrivate::blockModelSignals(bool block) |
|
156 | void QPieModelMapperPrivate::blockModelSignals(bool block) | |
163 | { |
|
157 | { | |
164 | m_modelSignalsBlock = block; |
|
158 | m_modelSignalsBlock = block; | |
165 | } |
|
159 | } | |
166 |
|
160 | |||
167 | void QPieModelMapperPrivate::blockSeriesSignals(bool block) |
|
161 | void QPieModelMapperPrivate::blockSeriesSignals(bool block) | |
168 | { |
|
162 | { | |
169 | m_seriesSignalsBlock = block; |
|
163 | m_seriesSignalsBlock = block; | |
170 | } |
|
164 | } | |
171 |
|
165 | |||
172 |
|
166 | |||
173 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const |
|
167 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const | |
174 | { |
|
168 | { | |
175 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesIndex || index.column() == m_labelsIndex)) { |
|
169 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesIndex || index.column() == m_labelsIndex)) { | |
176 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) |
|
170 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) | |
177 | return m_series->slices().at(index.row() - m_first); |
|
171 | return m_series->slices().at(index.row() - m_first); | |
178 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesIndex || index.row() == m_labelsIndex)) { |
|
172 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesIndex || index.row() == m_labelsIndex)) { | |
179 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
173 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |
180 | return m_series->slices().at(index.column() - m_first); |
|
174 | return m_series->slices().at(index.column() - m_first); | |
181 | } |
|
175 | } | |
182 | return 0; // This part of model has not been mapped to any slice |
|
176 | return 0; // This part of model has not been mapped to any slice | |
183 | } |
|
177 | } | |
184 |
|
178 | |||
185 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) |
|
179 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) | |
186 | { |
|
180 | { | |
187 | if (m_count != -1 && slicePos >= m_count) |
|
181 | if (m_count != -1 && slicePos >= m_count) | |
188 | return QModelIndex(); // invalid |
|
182 | return QModelIndex(); // invalid | |
189 |
|
183 | |||
190 | if (m_orientation == Qt::Vertical) |
|
184 | if (m_orientation == Qt::Vertical) | |
191 | return m_model->index(slicePos + m_first, m_valuesIndex); |
|
185 | return m_model->index(slicePos + m_first, m_valuesIndex); | |
192 | else |
|
186 | else | |
193 | return m_model->index(m_valuesIndex, slicePos + m_first); |
|
187 | return m_model->index(m_valuesIndex, slicePos + m_first); | |
194 | } |
|
188 | } | |
195 |
|
189 | |||
196 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) |
|
190 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) | |
197 | { |
|
191 | { | |
198 | if (m_count != -1 && slicePos >= m_count) |
|
192 | if (m_count != -1 && slicePos >= m_count) | |
199 | return QModelIndex(); // invalid |
|
193 | return QModelIndex(); // invalid | |
200 |
|
194 | |||
201 | if (m_orientation == Qt::Vertical) |
|
195 | if (m_orientation == Qt::Vertical) | |
202 | return m_model->index(slicePos + m_first, m_labelsIndex); |
|
196 | return m_model->index(slicePos + m_first, m_labelsIndex); | |
203 | else |
|
197 | else | |
204 | return m_model->index(m_labelsIndex, slicePos + m_first); |
|
198 | return m_model->index(m_labelsIndex, slicePos + m_first); | |
205 | } |
|
199 | } | |
206 |
|
200 | |||
207 | void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices) |
|
201 | void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices) | |
208 | { |
|
202 | { | |
209 | if (m_seriesSignalsBlock) |
|
203 | if (m_seriesSignalsBlock) | |
210 | return; |
|
204 | return; | |
211 |
|
205 | |||
212 | if (slices.count() == 0) |
|
206 | if (slices.count() == 0) | |
213 | return; |
|
207 | return; | |
214 |
|
208 | |||
215 | int firstIndex = m_series->slices().indexOf(slices.at(0)); |
|
209 | int firstIndex = m_series->slices().indexOf(slices.at(0)); | |
216 | if (firstIndex == -1) |
|
210 | if (firstIndex == -1) | |
217 | return; |
|
211 | return; | |
218 |
|
212 | |||
219 | if (m_count != -1) |
|
213 | if (m_count != -1) | |
220 | m_count += slices.count(); |
|
214 | m_count += slices.count(); | |
221 |
|
215 | |||
222 | for (int i = firstIndex; i < firstIndex + slices.count(); i++) { |
|
216 | for (int i = firstIndex; i < firstIndex + slices.count(); i++) { | |
223 | m_slices.insert(i, slices.at(i - firstIndex)); |
|
217 | m_slices.insert(i, slices.at(i - firstIndex)); | |
224 | connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
218 | connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
225 | connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
219 | connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
226 | } |
|
220 | } | |
227 |
|
221 | |||
228 | blockModelSignals(); |
|
222 | blockModelSignals(); | |
229 | if (m_orientation == Qt::Vertical) |
|
223 | if (m_orientation == Qt::Vertical) | |
230 | m_model->insertRows(firstIndex + m_first, slices.count()); |
|
224 | m_model->insertRows(firstIndex + m_first, slices.count()); | |
231 | else |
|
225 | else | |
232 | m_model->insertColumns(firstIndex + m_first, slices.count()); |
|
226 | m_model->insertColumns(firstIndex + m_first, slices.count()); | |
233 |
|
227 | |||
234 | for(int i = firstIndex; i < firstIndex + slices.count(); i++) { |
|
228 | for(int i = firstIndex; i < firstIndex + slices.count(); i++) { | |
235 | m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value()); |
|
229 | m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value()); | |
236 | m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label()); |
|
230 | m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label()); | |
237 | } |
|
231 | } | |
238 | blockModelSignals(false); |
|
232 | blockModelSignals(false); | |
239 | } |
|
233 | } | |
240 |
|
234 | |||
241 | void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices) |
|
235 | void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices) | |
242 | { |
|
236 | { | |
243 | if (m_seriesSignalsBlock) |
|
237 | if (m_seriesSignalsBlock) | |
244 | return; |
|
238 | return; | |
245 |
|
239 | |||
246 | if (slices.count() == 0) |
|
240 | if (slices.count() == 0) | |
247 | return; |
|
241 | return; | |
248 |
|
242 | |||
249 | int firstIndex = m_slices.indexOf(slices.at(0)); |
|
243 | int firstIndex = m_slices.indexOf(slices.at(0)); | |
250 | if (firstIndex == -1) |
|
244 | if (firstIndex == -1) | |
251 | return; |
|
245 | return; | |
252 |
|
246 | |||
253 | if (m_count != -1) |
|
247 | if (m_count != -1) | |
254 | m_count -= slices.count(); |
|
248 | m_count -= slices.count(); | |
255 |
|
249 | |||
256 | for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--) |
|
250 | for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--) | |
257 | m_slices.removeAt(i); |
|
251 | m_slices.removeAt(i); | |
258 |
|
252 | |||
259 | blockModelSignals(); |
|
253 | blockModelSignals(); | |
260 | if (m_orientation == Qt::Vertical) |
|
254 | if (m_orientation == Qt::Vertical) | |
261 | m_model->removeRows(firstIndex + m_first, slices.count()); |
|
255 | m_model->removeRows(firstIndex + m_first, slices.count()); | |
262 | else |
|
256 | else | |
263 | m_model->removeColumns(firstIndex + m_first, slices.count()); |
|
257 | m_model->removeColumns(firstIndex + m_first, slices.count()); | |
264 | blockModelSignals(false); |
|
258 | blockModelSignals(false); | |
265 | } |
|
259 | } | |
266 |
|
260 | |||
267 | void QPieModelMapperPrivate::sliceLabelChanged() |
|
261 | void QPieModelMapperPrivate::sliceLabelChanged() | |
268 | { |
|
262 | { | |
269 | if (m_seriesSignalsBlock) |
|
263 | if (m_seriesSignalsBlock) | |
270 | return; |
|
264 | return; | |
271 |
|
265 | |||
272 | blockModelSignals(); |
|
266 | blockModelSignals(); | |
273 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); |
|
267 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); | |
274 | m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label()); |
|
268 | m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label()); | |
275 | blockModelSignals(false); |
|
269 | blockModelSignals(false); | |
276 | } |
|
270 | } | |
277 |
|
271 | |||
278 | void QPieModelMapperPrivate::sliceValueChanged() |
|
272 | void QPieModelMapperPrivate::sliceValueChanged() | |
279 | { |
|
273 | { | |
280 | if (m_seriesSignalsBlock) |
|
274 | if (m_seriesSignalsBlock) | |
281 | return; |
|
275 | return; | |
282 |
|
276 | |||
283 | blockModelSignals(); |
|
277 | blockModelSignals(); | |
284 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); |
|
278 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); | |
285 | m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value()); |
|
279 | m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value()); | |
286 | blockModelSignals(false); |
|
280 | blockModelSignals(false); | |
287 | } |
|
281 | } | |
288 |
|
282 | |||
289 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
283 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
290 | { |
|
284 | { | |
291 | if (m_modelSignalsBlock) |
|
285 | if (m_modelSignalsBlock) | |
292 | return; |
|
286 | return; | |
293 |
|
287 | |||
294 | blockSeriesSignals(); |
|
288 | blockSeriesSignals(); | |
295 | QModelIndex index; |
|
289 | QModelIndex index; | |
296 | QPieSlice *slice; |
|
290 | QPieSlice *slice; | |
297 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
291 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
298 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
292 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
299 | index = topLeft.sibling(row, column); |
|
293 | index = topLeft.sibling(row, column); | |
300 | slice = pieSlice(index); |
|
294 | slice = pieSlice(index); | |
301 | if (slice) { |
|
295 | if (slice) { | |
302 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); |
|
296 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); | |
303 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); |
|
297 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); | |
304 | } |
|
298 | } | |
305 | } |
|
299 | } | |
306 | } |
|
300 | } | |
307 | blockSeriesSignals(false); |
|
301 | blockSeriesSignals(false); | |
308 | } |
|
302 | } | |
309 |
|
303 | |||
310 |
|
304 | |||
311 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
305 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
312 | { |
|
306 | { | |
313 | Q_UNUSED(parent); |
|
307 | Q_UNUSED(parent); | |
314 | if (m_modelSignalsBlock) |
|
308 | if (m_modelSignalsBlock) | |
315 | return; |
|
309 | return; | |
316 |
|
310 | |||
317 | blockSeriesSignals(); |
|
311 | blockSeriesSignals(); | |
318 | if (m_orientation == Qt::Vertical) |
|
312 | if (m_orientation == Qt::Vertical) | |
319 | insertData(start, end); |
|
313 | insertData(start, end); | |
320 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie |
|
314 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
321 | initializePieFromModel(); |
|
315 | initializePieFromModel(); | |
322 | blockSeriesSignals(false); |
|
316 | blockSeriesSignals(false); | |
323 | } |
|
317 | } | |
324 |
|
318 | |||
325 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
319 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
326 | { |
|
320 | { | |
327 | Q_UNUSED(parent); |
|
321 | Q_UNUSED(parent); | |
328 | if (m_modelSignalsBlock) |
|
322 | if (m_modelSignalsBlock) | |
329 | return; |
|
323 | return; | |
330 |
|
324 | |||
331 | blockSeriesSignals(); |
|
325 | blockSeriesSignals(); | |
332 | if (m_orientation == Qt::Vertical) |
|
326 | if (m_orientation == Qt::Vertical) | |
333 | removeData(start, end); |
|
327 | removeData(start, end); | |
334 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie |
|
328 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
335 | initializePieFromModel(); |
|
329 | initializePieFromModel(); | |
336 | blockSeriesSignals(false); |
|
330 | blockSeriesSignals(false); | |
337 | } |
|
331 | } | |
338 |
|
332 | |||
339 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
333 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
340 | { |
|
334 | { | |
341 | Q_UNUSED(parent); |
|
335 | Q_UNUSED(parent); | |
342 | if (m_modelSignalsBlock) |
|
336 | if (m_modelSignalsBlock) | |
343 | return; |
|
337 | return; | |
344 |
|
338 | |||
345 | blockSeriesSignals(); |
|
339 | blockSeriesSignals(); | |
346 | if (m_orientation == Qt::Horizontal) |
|
340 | if (m_orientation == Qt::Horizontal) | |
347 | insertData(start, end); |
|
341 | insertData(start, end); | |
348 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie |
|
342 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
349 | initializePieFromModel(); |
|
343 | initializePieFromModel(); | |
350 | blockSeriesSignals(false); |
|
344 | blockSeriesSignals(false); | |
351 | } |
|
345 | } | |
352 |
|
346 | |||
353 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
347 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
354 | { |
|
348 | { | |
355 | Q_UNUSED(parent); |
|
349 | Q_UNUSED(parent); | |
356 | if (m_modelSignalsBlock) |
|
350 | if (m_modelSignalsBlock) | |
357 | return; |
|
351 | return; | |
358 |
|
352 | |||
359 | blockSeriesSignals(); |
|
353 | blockSeriesSignals(); | |
360 | if (m_orientation == Qt::Horizontal) |
|
354 | if (m_orientation == Qt::Horizontal) | |
361 | removeData(start, end); |
|
355 | removeData(start, end); | |
362 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie |
|
356 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
363 | initializePieFromModel(); |
|
357 | initializePieFromModel(); | |
364 | blockSeriesSignals(false); |
|
358 | blockSeriesSignals(false); | |
365 | } |
|
359 | } | |
366 |
|
360 | |||
367 | void QPieModelMapperPrivate::insertData(int start, int end) |
|
361 | void QPieModelMapperPrivate::insertData(int start, int end) | |
368 | { |
|
362 | { | |
369 | if (m_count != -1 && start >= m_first + m_count) { |
|
363 | if (m_count != -1 && start >= m_first + m_count) { | |
370 | return; |
|
364 | return; | |
371 | } else { |
|
365 | } else { | |
372 | int addedCount = end - start + 1; |
|
366 | int addedCount = end - start + 1; | |
373 | if (m_count != -1 && addedCount > m_count) |
|
367 | if (m_count != -1 && addedCount > m_count) | |
374 | addedCount = m_count; |
|
368 | addedCount = m_count; | |
375 | int first = qMax(start, m_first); |
|
369 | int first = qMax(start, m_first); | |
376 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
370 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); | |
377 | for (int i = first; i <= last; i++) { |
|
371 | for (int i = first; i <= last; i++) { | |
378 | QPieSlice *slice = new QPieSlice; |
|
372 | QPieSlice *slice = new QPieSlice; | |
379 | slice->setValue(m_model->data(valueModelIndex(i - m_first), Qt::DisplayRole).toDouble()); |
|
373 | slice->setValue(m_model->data(valueModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
380 | slice->setLabel(m_model->data(labelModelIndex(i - m_first), Qt::DisplayRole).toString()); |
|
374 | slice->setLabel(m_model->data(labelModelIndex(i - m_first), Qt::DisplayRole).toString()); | |
381 | slice->setLabelVisible(); |
|
375 | slice->setLabelVisible(); | |
382 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
376 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
383 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
377 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
384 | m_series->insert(i - m_first, slice); |
|
378 | m_series->insert(i - m_first, slice); | |
385 | m_slices.insert(i - m_first, slice); |
|
379 | m_slices.insert(i - m_first, slice); | |
386 | } |
|
380 | } | |
387 |
|
381 | |||
388 | // remove excess of slices (abouve m_count) |
|
382 | // remove excess of slices (abouve m_count) | |
389 | if (m_count != -1 && m_series->slices().size() > m_count) |
|
383 | if (m_count != -1 && m_series->slices().size() > m_count) | |
390 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) { |
|
384 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) { | |
391 | m_series->remove(m_series->slices().at(i)); |
|
385 | m_series->remove(m_series->slices().at(i)); | |
392 | m_slices.removeAt(i); |
|
386 | m_slices.removeAt(i); | |
393 | } |
|
387 | } | |
394 | } |
|
388 | } | |
395 | } |
|
389 | } | |
396 |
|
390 | |||
397 | void QPieModelMapperPrivate::removeData(int start, int end) |
|
391 | void QPieModelMapperPrivate::removeData(int start, int end) | |
398 | { |
|
392 | { | |
399 | int removedCount = end - start + 1; |
|
393 | int removedCount = end - start + 1; | |
400 | if (m_count != -1 && start >= m_first + m_count) { |
|
394 | if (m_count != -1 && start >= m_first + m_count) { | |
401 | return; |
|
395 | return; | |
402 | } else { |
|
396 | } else { | |
403 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed |
|
397 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed | |
404 | int first = qMax(start, m_first); // get the index of the first item that will be removed. |
|
398 | int first = qMax(start, m_first); // get the index of the first item that will be removed. | |
405 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. |
|
399 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. | |
406 | for (int i = last; i >= first; i--) { |
|
400 | for (int i = last; i >= first; i--) { | |
407 | m_series->remove(m_series->slices().at(i - m_first)); |
|
401 | m_series->remove(m_series->slices().at(i - m_first)); | |
408 | m_slices.removeAt(i - m_first); |
|
402 | m_slices.removeAt(i - m_first); | |
409 | } |
|
403 | } | |
410 |
|
404 | |||
411 | if (m_count != -1) { |
|
405 | if (m_count != -1) { | |
412 | int itemsAvailable; // check how many are available to be added |
|
406 | int itemsAvailable; // check how many are available to be added | |
413 | if (m_orientation == Qt::Vertical) |
|
407 | if (m_orientation == Qt::Vertical) | |
414 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); |
|
408 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); | |
415 | else |
|
409 | else | |
416 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); |
|
410 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); | |
417 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. |
|
411 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. | |
418 | int currentSize = m_series->slices().size(); |
|
412 | int currentSize = m_series->slices().size(); | |
419 | if (toBeAdded > 0) |
|
413 | if (toBeAdded > 0) | |
420 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { |
|
414 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { | |
421 | QPieSlice *slice = new QPieSlice; |
|
415 | QPieSlice *slice = new QPieSlice; | |
422 | if (m_orientation == Qt::Vertical) { |
|
416 | if (m_orientation == Qt::Vertical) { | |
423 | slice->setValue(m_model->data(m_model->index(i + m_first, m_valuesIndex), Qt::DisplayRole).toDouble()); |
|
417 | slice->setValue(m_model->data(m_model->index(i + m_first, m_valuesIndex), Qt::DisplayRole).toDouble()); | |
424 | slice->setLabel(m_model->data(m_model->index(i + m_first, m_labelsIndex), Qt::DisplayRole).toString()); |
|
418 | slice->setLabel(m_model->data(m_model->index(i + m_first, m_labelsIndex), Qt::DisplayRole).toString()); | |
425 | } else { |
|
419 | } else { | |
426 | slice->setValue(m_model->data(m_model->index(m_valuesIndex, i + m_first), Qt::DisplayRole).toDouble()); |
|
420 | slice->setValue(m_model->data(m_model->index(m_valuesIndex, i + m_first), Qt::DisplayRole).toDouble()); | |
427 | slice->setLabel(m_model->data(m_model->index(m_labelsIndex, i + m_first), Qt::DisplayRole).toString()); |
|
421 | slice->setLabel(m_model->data(m_model->index(m_labelsIndex, i + m_first), Qt::DisplayRole).toString()); | |
428 | } |
|
422 | } | |
429 | slice->setLabelVisible(); |
|
423 | slice->setLabelVisible(); | |
430 | m_series->insert(i, slice); |
|
424 | m_series->insert(i, slice); | |
431 | m_slices.insert(i, slice); |
|
425 | m_slices.insert(i, slice); | |
432 | } |
|
426 | } | |
433 | } |
|
427 | } | |
434 | } |
|
428 | } | |
435 | } |
|
429 | } | |
436 |
|
430 | |||
437 | void QPieModelMapperPrivate::initializePieFromModel() |
|
431 | void QPieModelMapperPrivate::initializePieFromModel() | |
438 | { |
|
432 | { | |
439 | if (m_model == 0 || m_series == 0) |
|
433 | if (m_model == 0 || m_series == 0) | |
440 | return; |
|
434 | return; | |
441 |
|
435 | |||
442 | // check if mappings are set |
|
|||
443 | if (m_valuesIndex == -1 || m_labelsIndex == -1) |
|
|||
444 | return; |
|
|||
445 |
|
||||
446 | blockSeriesSignals(); |
|
436 | blockSeriesSignals(); | |
447 | // clear current content |
|
437 | // clear current content | |
448 | m_series->clear(); |
|
438 | m_series->clear(); | |
449 | m_slices.clear(); |
|
439 | m_slices.clear(); | |
450 |
|
440 | |||
451 | // create the initial slices set |
|
441 | // create the initial slices set | |
452 | int slicePos = 0; |
|
442 | int slicePos = 0; | |
453 | QModelIndex valueIndex = valueModelIndex(slicePos); |
|
443 | QModelIndex valueIndex = valueModelIndex(slicePos); | |
454 | QModelIndex labelIndex = labelModelIndex(slicePos); |
|
444 | QModelIndex labelIndex = labelModelIndex(slicePos); | |
455 | while (valueIndex.isValid() && labelIndex.isValid()) { |
|
445 | while (valueIndex.isValid() && labelIndex.isValid()) { | |
456 | QPieSlice *slice = new QPieSlice; |
|
446 | QPieSlice *slice = new QPieSlice; | |
457 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
447 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); | |
458 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
448 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
459 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
449 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
460 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
450 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
461 | m_series->append(slice); |
|
451 | m_series->append(slice); | |
462 | m_slices.append(slice); |
|
452 | m_slices.append(slice); | |
463 | // m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
453 | // m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
464 | slicePos++; |
|
454 | slicePos++; | |
465 | valueIndex = valueModelIndex(slicePos); |
|
455 | valueIndex = valueModelIndex(slicePos); | |
466 | labelIndex = labelModelIndex(slicePos); |
|
456 | labelIndex = labelModelIndex(slicePos); | |
467 | } |
|
457 | } | |
468 | m_series->setLabelsVisible(true); |
|
458 | m_series->setLabelsVisible(true); | |
469 | blockSeriesSignals(false); |
|
459 | blockSeriesSignals(false); | |
470 | } |
|
460 | } | |
471 |
|
461 | |||
472 | #include "moc_qpiemodelmapper_p.cpp" |
|
462 | #include "moc_qpiemodelmapper_p.cpp" | |
473 | #include "moc_qpiemodelmapper.cpp" |
|
463 | #include "moc_qpiemodelmapper.cpp" | |
474 |
|
464 | |||
475 | QTCOMMERCIALCHART_END_NAMESPACE |
|
465 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,10 +1,10 | |||||
1 | !include( ../tests.pri ) { |
|
1 | !include( ../tests.pri ) { | |
2 | error( "Couldn't find the tests.pri file!" ) |
|
2 | error( "Couldn't find the tests.pri file!" ) | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | TEMPLATE = subdirs |
|
5 | TEMPLATE = subdirs | |
6 | SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qstackedbarseries qpercentbarseries qgroupedbarseries qpieslice qpieseries |
|
6 | SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qstackedbarseries qpercentbarseries qgroupedbarseries qpieslice qpieseries qpiemodelmapper | |
7 |
|
7 | |||
8 | test_private:{ |
|
8 | test_private:{ | |
9 | SUBDIRS += chartdataset domain |
|
9 | SUBDIRS += chartdataset domain | |
10 | } |
|
10 | } |
@@ -1,519 +1,519 | |||||
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 <QChart> |
|
24 | #include <QChart> | |
25 | #include <QStyledItemDelegate> |
|
25 | #include <QStyledItemDelegate> | |
26 | #include <QLineSeries> |
|
26 | #include <QLineSeries> | |
27 | #include <QSplineSeries> |
|
27 | #include <QSplineSeries> | |
28 | #include <QScatterSeries> |
|
28 | #include <QScatterSeries> | |
29 | #include <QXYModelMapper> |
|
29 | #include <QXYModelMapper> | |
30 | #include "customtablemodel.h" |
|
30 | #include "customtablemodel.h" | |
31 | #include <QPieSeries> |
|
31 | #include <QPieSeries> | |
32 | #include <QVPieModelMapper> |
|
32 | #include <QVPieModelMapper> | |
33 | #include <QPieSlice> |
|
33 | #include <QPieSlice> | |
34 | #include <QAreaSeries> |
|
34 | #include <QAreaSeries> | |
35 | #include <QBarSeries> |
|
35 | #include <QBarSeries> | |
36 | #include <QGroupedBarSeries> |
|
36 | #include <QGroupedBarSeries> | |
37 | #include <QBarSet> |
|
37 | #include <QBarSet> | |
38 | #include <QBarModelMapper> |
|
38 | #include <QBarModelMapper> | |
39 | #include <QPushButton> |
|
39 | #include <QPushButton> | |
40 | #include <QRadioButton> |
|
40 | #include <QRadioButton> | |
41 | #include <QLabel> |
|
41 | #include <QLabel> | |
42 | #include <QSpinBox> |
|
42 | #include <QSpinBox> | |
43 | #include <QTime> |
|
43 | #include <QTime> | |
44 | #include <QHeaderView> |
|
44 | #include <QHeaderView> | |
45 |
|
45 | |||
46 | TableWidget::TableWidget(QWidget *parent) |
|
46 | TableWidget::TableWidget(QWidget *parent) | |
47 | : QWidget(parent) |
|
47 | : QWidget(parent) | |
48 | // specialPie(0) |
|
48 | // specialPie(0) | |
49 | { |
|
49 | { | |
50 | setGeometry(1900, 100, 1000, 600); |
|
50 | setGeometry(1900, 100, 1000, 600); | |
51 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
51 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
52 | // create simple model for storing data |
|
52 | // create simple model for storing data | |
53 | // user's table data model |
|
53 | // user's table data model | |
54 | m_model = new CustomTableModel; |
|
54 | m_model = new CustomTableModel; | |
55 | m_tableView = new QTableView; |
|
55 | m_tableView = new QTableView; | |
56 | m_tableView->setModel(m_model); |
|
56 | m_tableView->setModel(m_model); | |
57 | // m_tableView->setMinimumHeight(300); |
|
57 | // m_tableView->setMinimumHeight(300); | |
58 | m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
58 | m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |
59 | m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
59 | m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |
60 |
|
60 | |||
61 | m_chart = new QChart; |
|
61 | m_chart = new QChart; | |
62 | m_chart->legend()->setVisible(true); |
|
62 | m_chart->legend()->setVisible(true); | |
63 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
63 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
64 | m_chartView = new QChartView(m_chart); |
|
64 | m_chartView = new QChartView(m_chart); | |
65 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
65 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
66 | m_chartView->setMinimumSize(640, 480); |
|
66 | m_chartView->setMinimumSize(640, 480); | |
67 |
|
67 | |||
68 | // add, remove data buttons |
|
68 | // add, remove data buttons | |
69 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
69 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); | |
70 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
70 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); | |
71 |
|
71 | |||
72 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
72 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); | |
73 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
73 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); | |
74 |
|
74 | |||
75 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
75 | QPushButton* removeRowButton = new QPushButton("Remove row"); | |
76 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
76 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); | |
77 |
|
77 | |||
78 | QPushButton* addColumnRightButton = new QPushButton("Add column to the right"); |
|
78 | QPushButton* addColumnRightButton = new QPushButton("Add column to the right"); | |
79 | connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight())); |
|
79 | connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight())); | |
80 |
|
80 | |||
81 | QPushButton* removeColumnButton = new QPushButton("Remove column"); |
|
81 | QPushButton* removeColumnButton = new QPushButton("Remove column"); | |
82 | connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn())); |
|
82 | connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn())); | |
83 |
|
83 | |||
84 | QPushButton* specialPieButton = new QPushButton("Add slices from series"); |
|
84 | QPushButton* specialPieButton = new QPushButton("Add slices from series"); | |
85 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); |
|
85 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); | |
86 |
|
86 | |||
87 | QPushButton* specialPieButton2 = new QPushButton("Remove slices from series"); |
|
87 | QPushButton* specialPieButton2 = new QPushButton("Remove slices from series"); | |
88 | connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2())); |
|
88 | connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2())); | |
89 |
|
89 | |||
90 | QPushButton* specialPieButton3 = new QPushButton("Remove slices from series"); |
|
90 | QPushButton* specialPieButton3 = new QPushButton("Remove slices from series"); | |
91 | connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3())); |
|
91 | connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3())); | |
92 |
|
92 | |||
93 |
|
93 | |||
94 | // QLabel *spinBoxLabel = new QLabel("Rows affected:"); |
|
94 | // QLabel *spinBoxLabel = new QLabel("Rows affected:"); | |
95 |
|
95 | |||
96 | // spin box for setting number of affected items (add, remove) |
|
96 | // spin box for setting number of affected items (add, remove) | |
97 | m_linesCountSpinBox = new QSpinBox; |
|
97 | m_linesCountSpinBox = new QSpinBox; | |
98 | m_linesCountSpinBox->setRange(1, 10); |
|
98 | m_linesCountSpinBox->setRange(1, 10); | |
99 | m_linesCountSpinBox->setValue(1); |
|
99 | m_linesCountSpinBox->setValue(1); | |
100 |
|
100 | |||
101 | // buttons layout |
|
101 | // buttons layout | |
102 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
102 | QVBoxLayout* buttonsLayout = new QVBoxLayout; | |
103 | // buttonsLayout->addWidget(spinBoxLabel); |
|
103 | // buttonsLayout->addWidget(spinBoxLabel); | |
104 | // buttonsLayout->addWidget(m_linesCountSpinBox); |
|
104 | // buttonsLayout->addWidget(m_linesCountSpinBox); | |
105 | // buttonsLayout->addWidget(addRowAboveButton); |
|
105 | // buttonsLayout->addWidget(addRowAboveButton); | |
106 | buttonsLayout->addWidget(addRowBelowButton); |
|
106 | buttonsLayout->addWidget(addRowBelowButton); | |
107 | buttonsLayout->addWidget(removeRowButton); |
|
107 | buttonsLayout->addWidget(removeRowButton); | |
108 | // buttonsLayout->addWidget(addColumnRightButton); |
|
108 | // buttonsLayout->addWidget(addColumnRightButton); | |
109 | // buttonsLayout->addWidget(removeColumnButton); |
|
109 | // buttonsLayout->addWidget(removeColumnButton); | |
110 | buttonsLayout->addWidget(specialPieButton); |
|
110 | buttonsLayout->addWidget(specialPieButton); | |
111 | buttonsLayout->addWidget(specialPieButton2); |
|
111 | buttonsLayout->addWidget(specialPieButton2); | |
112 | buttonsLayout->addWidget(specialPieButton3); |
|
112 | buttonsLayout->addWidget(specialPieButton3); | |
113 | buttonsLayout->addStretch(); |
|
113 | buttonsLayout->addStretch(); | |
114 |
|
114 | |||
115 | // chart type radio buttons |
|
115 | // chart type radio buttons | |
116 | m_lineRadioButton = new QRadioButton("Line"); |
|
116 | m_lineRadioButton = new QRadioButton("Line"); | |
117 | m_splineRadioButton = new QRadioButton("Spline"); |
|
117 | m_splineRadioButton = new QRadioButton("Spline"); | |
118 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
118 | m_scatterRadioButton = new QRadioButton("Scatter"); | |
119 | m_pieRadioButton = new QRadioButton("Pie"); |
|
119 | m_pieRadioButton = new QRadioButton("Pie"); | |
120 | m_areaRadioButton = new QRadioButton("Area"); |
|
120 | m_areaRadioButton = new QRadioButton("Area"); | |
121 | m_barRadioButton = new QRadioButton("Bar"); |
|
121 | m_barRadioButton = new QRadioButton("Bar"); | |
122 |
|
122 | |||
123 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
123 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
124 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
124 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
125 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
125 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
126 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
126 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
127 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
127 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
128 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
128 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
129 | m_lineRadioButton->setChecked(true); |
|
129 | m_lineRadioButton->setChecked(true); | |
130 |
|
130 | |||
131 | // radio buttons layout |
|
131 | // radio buttons layout | |
132 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
132 | QVBoxLayout* radioLayout = new QVBoxLayout; | |
133 | radioLayout->addWidget(m_lineRadioButton); |
|
133 | radioLayout->addWidget(m_lineRadioButton); | |
134 | radioLayout->addWidget(m_splineRadioButton); |
|
134 | radioLayout->addWidget(m_splineRadioButton); | |
135 | // radioLayout->addWidget(m_scatterRadioButton); |
|
135 | // radioLayout->addWidget(m_scatterRadioButton); | |
136 | radioLayout->addWidget(m_pieRadioButton); |
|
136 | radioLayout->addWidget(m_pieRadioButton); | |
137 | // radioLayout->addWidget(m_areaRadioButton); |
|
137 | // radioLayout->addWidget(m_areaRadioButton); | |
138 | radioLayout->addWidget(m_barRadioButton); |
|
138 | radioLayout->addWidget(m_barRadioButton); | |
139 | radioLayout->addStretch(); |
|
139 | radioLayout->addStretch(); | |
140 |
|
140 | |||
141 | // create main layout |
|
141 | // create main layout | |
142 | QGridLayout* mainLayout = new QGridLayout; |
|
142 | QGridLayout* mainLayout = new QGridLayout; | |
143 | mainLayout->addLayout(buttonsLayout, 2, 0); |
|
143 | mainLayout->addLayout(buttonsLayout, 2, 0); | |
144 | mainLayout->addLayout(radioLayout, 3, 0); |
|
144 | mainLayout->addLayout(radioLayout, 3, 0); | |
145 | mainLayout->addWidget(m_tableView, 1, 0); |
|
145 | mainLayout->addWidget(m_tableView, 1, 0); | |
146 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); |
|
146 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); | |
147 | setLayout(mainLayout); |
|
147 | setLayout(mainLayout); | |
148 | m_lineRadioButton->setFocus(); |
|
148 | m_lineRadioButton->setFocus(); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void TableWidget::addRowAbove() |
|
151 | void TableWidget::addRowAbove() | |
152 | { |
|
152 | { | |
153 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
153 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); | |
154 |
|
154 | |||
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void TableWidget::addRowBelow() |
|
157 | void TableWidget::addRowBelow() | |
158 | { |
|
158 | { | |
159 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
159 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); | |
160 |
|
160 | |||
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | void TableWidget::removeRow() |
|
163 | void TableWidget::removeRow() | |
164 | { |
|
164 | { | |
165 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
165 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void TableWidget::addColumnRight() |
|
168 | void TableWidget::addColumnRight() | |
169 | { |
|
169 | { | |
170 | m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); |
|
170 | m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void TableWidget::removeColumn() |
|
173 | void TableWidget::removeColumn() | |
174 | { |
|
174 | { | |
175 | m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); |
|
175 | m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | void TableWidget::updateChartType(bool toggle) |
|
178 | void TableWidget::updateChartType(bool toggle) | |
179 | { |
|
179 | { | |
180 | // this if is needed, so that the function is only called once. |
|
180 | // this if is needed, so that the function is only called once. | |
181 | // For the radioButton that was enabled. |
|
181 | // For the radioButton that was enabled. | |
182 | if (toggle) { |
|
182 | if (toggle) { | |
183 | // specialPie = 0; |
|
183 | // specialPie = 0; | |
184 | m_chart->removeAllSeries(); |
|
184 | m_chart->removeAllSeries(); | |
185 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
185 | // m_chart->axisX()->setNiceNumbersEnabled(false); | |
186 | // m_chart->axisY()->setNiceNumbersEnabled(false); |
|
186 | // m_chart->axisY()->setNiceNumbersEnabled(false); | |
187 |
|
187 | |||
188 | // // renable axes of the chart (pie hides them) |
|
188 | // // renable axes of the chart (pie hides them) | |
189 | // // x axis |
|
189 | // // x axis | |
190 | // QAxis *axis = m_chart->axisX(); |
|
190 | // QAxis *axis = m_chart->axisX(); | |
191 | // axis->setAxisVisible(true); |
|
191 | // axis->setAxisVisible(true); | |
192 | // axis->setGridLineVisible(true); |
|
192 | // axis->setGridLineVisible(true); | |
193 | // axis->setLabelsVisible(true); |
|
193 | // axis->setLabelsVisible(true); | |
194 |
|
194 | |||
195 | // // y axis |
|
195 | // // y axis | |
196 | // axis = m_chart->axisY(); |
|
196 | // axis = m_chart->axisY(); | |
197 | // axis->setAxisVisible(true); |
|
197 | // axis->setAxisVisible(true); | |
198 | // axis->setGridLineVisible(true); |
|
198 | // axis->setGridLineVisible(true); | |
199 | // axis->setLabelsVisible(true); |
|
199 | // axis->setLabelsVisible(true); | |
200 |
|
200 | |||
201 | // m_model->clearMapping(); |
|
201 | // m_model->clearMapping(); | |
202 |
|
202 | |||
203 | QString seriesColorHex = "#000000"; |
|
203 | QString seriesColorHex = "#000000"; | |
204 | // QPen pen; |
|
204 | // QPen pen; | |
205 | // pen.setWidth(2); |
|
205 | // pen.setWidth(2); | |
206 |
|
206 | |||
207 | if (m_lineRadioButton->isChecked()) |
|
207 | if (m_lineRadioButton->isChecked()) | |
208 | { |
|
208 | { | |
209 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
209 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
210 |
|
210 | |||
211 | // // series 1 |
|
211 | // // series 1 | |
212 | // m_series = new QLineSeries; |
|
212 | // m_series = new QLineSeries; | |
213 | // m_series->setModel(m_model); |
|
213 | // m_series->setModel(m_model); | |
214 |
|
214 | |||
215 | // QXYModelMapper *mapper = new QXYModelMapper; |
|
215 | // QXYModelMapper *mapper = new QXYModelMapper; | |
216 | // mapper->setMapX(0); |
|
216 | // mapper->setMapX(0); | |
217 | // mapper->setMapY(1); |
|
217 | // mapper->setMapY(1); | |
218 | // mapper->setFirst(3); |
|
218 | // mapper->setFirst(3); | |
219 | // mapper->setCount(4); |
|
219 | // mapper->setCount(4); | |
220 | // m_series->setModelMapper(mapper); |
|
220 | // m_series->setModelMapper(mapper); | |
221 | // // m_series->setModelMapping(0,1, Qt::Vertical); |
|
221 | // // m_series->setModelMapping(0,1, Qt::Vertical); | |
222 | // // m_series->setModelMappingRange(3, 4); |
|
222 | // // m_series->setModelMappingRange(3, 4); | |
223 | // m_chart->addSeries(m_series); |
|
223 | // m_chart->addSeries(m_series); | |
224 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
224 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
225 | // m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); |
|
225 | // m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); | |
226 |
|
226 | |||
227 | // // series 2 |
|
227 | // // series 2 | |
228 | // m_series = new QLineSeries; |
|
228 | // m_series = new QLineSeries; | |
229 | // m_series->setModel(m_model); |
|
229 | // m_series->setModel(m_model); | |
230 |
|
230 | |||
231 | // mapper = new QXYModelMapper; |
|
231 | // mapper = new QXYModelMapper; | |
232 | // mapper->setMapX(3); |
|
232 | // mapper->setMapX(3); | |
233 | // mapper->setMapY(4); |
|
233 | // mapper->setMapY(4); | |
234 | // // mapper->setFirst(3); |
|
234 | // // mapper->setFirst(3); | |
235 | // // mapper->setCount(4); |
|
235 | // // mapper->setCount(4); | |
236 | // m_series->setModelMapper(mapper); |
|
236 | // m_series->setModelMapper(mapper); | |
237 | // // m_series->setModelMapping(2,3, Qt::Vertical); |
|
237 | // // m_series->setModelMapping(2,3, Qt::Vertical); | |
238 | // m_chart->addSeries(m_series); |
|
238 | // m_chart->addSeries(m_series); | |
239 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
239 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
240 | // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); |
|
240 | // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); | |
241 |
|
241 | |||
242 | // // series 3 |
|
242 | // // series 3 | |
243 | // m_series = new QLineSeries; |
|
243 | // m_series = new QLineSeries; | |
244 | // m_series->setModel(m_model); |
|
244 | // m_series->setModel(m_model); | |
245 |
|
245 | |||
246 | // mapper = new QXYModelMapper; |
|
246 | // mapper = new QXYModelMapper; | |
247 | // mapper->setMapX(5); |
|
247 | // mapper->setMapX(5); | |
248 | // mapper->setMapY(6); |
|
248 | // mapper->setMapY(6); | |
249 | // mapper->setFirst(2); |
|
249 | // mapper->setFirst(2); | |
250 | // mapper->setCount(-1); |
|
250 | // mapper->setCount(-1); | |
251 | // m_series->setModelMapper(mapper); |
|
251 | // m_series->setModelMapper(mapper); | |
252 | // // m_series->setModelMapping(4,5, Qt::Vertical); |
|
252 | // // m_series->setModelMapping(4,5, Qt::Vertical); | |
253 | // // m_series->setModelMappingRange(2, -1); |
|
253 | // // m_series->setModelMappingRange(2, -1); | |
254 | // m_chart->addSeries(m_series); |
|
254 | // m_chart->addSeries(m_series); | |
255 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
255 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
256 | // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); |
|
256 | // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); | |
257 | } |
|
257 | } | |
258 | else if (m_splineRadioButton->isChecked()) |
|
258 | else if (m_splineRadioButton->isChecked()) | |
259 | { |
|
259 | { | |
260 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
260 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
261 |
|
261 | |||
262 | // // series 1 |
|
262 | // // series 1 | |
263 | // m_series = new QSplineSeries; |
|
263 | // m_series = new QSplineSeries; | |
264 | // m_series->setModel(m_model); |
|
264 | // m_series->setModel(m_model); | |
265 |
|
265 | |||
266 | // QXYModelMapper *mapper = new QXYModelMapper; |
|
266 | // QXYModelMapper *mapper = new QXYModelMapper; | |
267 | // mapper->setMapX(0); |
|
267 | // mapper->setMapX(0); | |
268 | // mapper->setMapY(1); |
|
268 | // mapper->setMapY(1); | |
269 | // mapper->setFirst(0); |
|
269 | // mapper->setFirst(0); | |
270 | // mapper->setCount(-1); |
|
270 | // mapper->setCount(-1); | |
271 |
|
271 | |||
272 | // m_series->setModelMapper(mapper); |
|
272 | // m_series->setModelMapper(mapper); | |
273 |
|
273 | |||
274 | // m_chart->addSeries(m_series); |
|
274 | // m_chart->addSeries(m_series); | |
275 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
275 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
276 | // m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); |
|
276 | // m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); | |
277 |
|
277 | |||
278 | // // series 2 |
|
278 | // // series 2 | |
279 | // m_series = new QSplineSeries; |
|
279 | // m_series = new QSplineSeries; | |
280 | // m_series->setModel(m_model); |
|
280 | // m_series->setModel(m_model); | |
281 |
|
281 | |||
282 | // mapper = new QXYModelMapper; |
|
282 | // mapper = new QXYModelMapper; | |
283 | // mapper->setMapX(2); |
|
283 | // mapper->setMapX(2); | |
284 | // mapper->setMapY(3); |
|
284 | // mapper->setMapY(3); | |
285 | // mapper->setFirst(2); |
|
285 | // mapper->setFirst(2); | |
286 | // mapper->setCount(4); |
|
286 | // mapper->setCount(4); | |
287 |
|
287 | |||
288 | // m_series->setModelMapper(mapper); |
|
288 | // m_series->setModelMapper(mapper); | |
289 |
|
289 | |||
290 | // m_chart->addSeries(m_series); |
|
290 | // m_chart->addSeries(m_series); | |
291 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
291 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
292 | // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); |
|
292 | // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); | |
293 |
|
293 | |||
294 | // // series 3 |
|
294 | // // series 3 | |
295 | // m_series = new QSplineSeries; |
|
295 | // m_series = new QSplineSeries; | |
296 | // m_series->setModel(m_model); |
|
296 | // m_series->setModel(m_model); | |
297 |
|
297 | |||
298 | // mapper = new QXYModelMapper; |
|
298 | // mapper = new QXYModelMapper; | |
299 | // mapper->setMapX(4); |
|
299 | // mapper->setMapX(4); | |
300 | // mapper->setMapY(5); |
|
300 | // mapper->setMapY(5); | |
301 | // mapper->setFirst(2); |
|
301 | // mapper->setFirst(2); | |
302 | // mapper->setCount(-1); |
|
302 | // mapper->setCount(-1); | |
303 |
|
303 | |||
304 | // m_series->setModelMapper(mapper); |
|
304 | // m_series->setModelMapper(mapper); | |
305 |
|
305 | |||
306 | // m_chart->addSeries(m_series); |
|
306 | // m_chart->addSeries(m_series); | |
307 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
307 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
308 | // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
308 | // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
309 | } |
|
309 | } | |
310 | // else if (m_scatterRadioButton->isChecked()) |
|
310 | // else if (m_scatterRadioButton->isChecked()) | |
311 | // { |
|
311 | // { | |
312 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
312 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
313 |
|
313 | |||
314 | // // series 1 |
|
314 | // // series 1 | |
315 | // m_series = new QScatterSeries; |
|
315 | // m_series = new QScatterSeries; | |
316 | // m_series->setModel(m_model); |
|
316 | // m_series->setModel(m_model); | |
317 | // m_series->setModelMapping(0,1, Qt::Vertical); |
|
317 | // m_series->setModelMapping(0,1, Qt::Vertical); | |
318 | // // m_series->setModelMappingRange(2, 0); |
|
318 | // // m_series->setModelMappingRange(2, 0); | |
319 | // // series->setModelMapping(0,1, Qt::Horizontal); |
|
319 | // // series->setModelMapping(0,1, Qt::Horizontal); | |
320 | // m_chart->addSeries(m_series); |
|
320 | // m_chart->addSeries(m_series); | |
321 |
|
321 | |||
322 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
322 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
323 | // m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
323 | // m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); | |
324 |
|
324 | |||
325 | // // series 2 |
|
325 | // // series 2 | |
326 | // m_series = new QScatterSeries; |
|
326 | // m_series = new QScatterSeries; | |
327 | // m_series->setModel(m_model); |
|
327 | // m_series->setModel(m_model); | |
328 | // m_series->setModelMapping(2,3, Qt::Vertical); |
|
328 | // m_series->setModelMapping(2,3, Qt::Vertical); | |
329 | // // m_series->setModelMappingRange(1, 6); |
|
329 | // // m_series->setModelMappingRange(1, 6); | |
330 | // // series->setModelMapping(2,3, Qt::Horizontal); |
|
330 | // // series->setModelMapping(2,3, Qt::Horizontal); | |
331 | // m_chart->addSeries(m_series); |
|
331 | // m_chart->addSeries(m_series); | |
332 |
|
332 | |||
333 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
333 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
334 | // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
334 | // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); | |
335 |
|
335 | |||
336 | // // series 3 |
|
336 | // // series 3 | |
337 | // m_series = new QScatterSeries; |
|
337 | // m_series = new QScatterSeries; | |
338 | // m_series->setModel(m_model); |
|
338 | // m_series->setModel(m_model); | |
339 | // m_series->setModelMapping(4,5, Qt::Vertical); |
|
339 | // m_series->setModelMapping(4,5, Qt::Vertical); | |
340 | // // series->setModelMapping(4,5, Qt::Horizontal); |
|
340 | // // series->setModelMapping(4,5, Qt::Horizontal); | |
341 | // m_chart->addSeries(m_series); |
|
341 | // m_chart->addSeries(m_series); | |
342 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
342 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
343 | // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
343 | // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); | |
344 | // } |
|
344 | // } | |
345 | else if (m_pieRadioButton->isChecked()) |
|
345 | else if (m_pieRadioButton->isChecked()) | |
346 | { |
|
346 | { | |
347 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
347 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
348 |
|
348 | |||
349 | // pie 1 |
|
349 | // pie 1 | |
350 | m_pieSeries = new QPieSeries; |
|
350 | m_pieSeries = new QPieSeries; | |
351 |
|
351 | |||
352 | m_pieMapper = new QVPieModelMapper; |
|
352 | m_pieMapper = new QVPieModelMapper; | |
353 | m_pieMapper->setValuesColumn(1); |
|
353 | m_pieMapper->setValuesColumn(1); | |
354 | m_pieMapper->setLabelsColumn(7); |
|
354 | m_pieMapper->setLabelsColumn(7); | |
355 | m_pieMapper->setSeries(m_pieSeries); |
|
355 | m_pieMapper->setSeries(m_pieSeries); | |
356 | m_pieMapper->setModel(m_model); |
|
356 | m_pieMapper->setModel(m_model); | |
357 | m_pieMapper->setFirst(2); |
|
357 | m_pieMapper->setFirst(2); | |
358 | m_pieMapper->setCount(5); |
|
358 | // m_pieMapper->setCount(5); | |
359 | // pieSeries->setModelMapper(mapper); |
|
359 | // pieSeries->setModelMapper(mapper); | |
360 |
|
360 | |||
361 | m_pieSeries->setLabelsVisible(true); |
|
361 | m_pieSeries->setLabelsVisible(true); | |
362 | m_pieSeries->setPieSize(0.75); |
|
362 | m_pieSeries->setPieSize(0.75); | |
363 | // pieSeries->setHorizontalPosition(0.2); |
|
363 | // pieSeries->setHorizontalPosition(0.2); | |
364 | // pieSeries->setVerticalPosition(0.3); |
|
364 | // pieSeries->setVerticalPosition(0.3); | |
365 |
|
365 | |||
366 | m_chart->addSeries(m_pieSeries); |
|
366 | m_chart->addSeries(m_pieSeries); | |
367 | seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
367 | seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
368 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5)); |
|
368 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5)); | |
369 |
|
369 | |||
370 |
|
370 | |||
371 | // pieSeries->slices().at(0)->setValue(400); |
|
371 | // pieSeries->slices().at(0)->setValue(400); | |
372 | // pieSeries->slices().at(0)->setLabel(QString("36")); |
|
372 | // pieSeries->slices().at(0)->setLabel(QString("36")); | |
373 |
|
373 | |||
374 | // // pie 2 |
|
374 | // // pie 2 | |
375 | // pieSeries = new QPieSeries; |
|
375 | // pieSeries = new QPieSeries; | |
376 | // pieSeries->setModel(m_model); |
|
376 | // pieSeries->setModel(m_model); | |
377 |
|
377 | |||
378 | // pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
378 | // pieSeries->setModelMapping(1,1, Qt::Vertical); | |
379 | // pieSeries->setModelMappingRange(2, -1); |
|
379 | // pieSeries->setModelMappingRange(2, -1); | |
380 | // pieSeries->setLabelsVisible(true); |
|
380 | // pieSeries->setLabelsVisible(true); | |
381 | // pieSeries->setPieSize(0.35); |
|
381 | // pieSeries->setPieSize(0.35); | |
382 | // pieSeries->setHorizontalPosition(0.8); |
|
382 | // pieSeries->setHorizontalPosition(0.8); | |
383 | // pieSeries->setVerticalPosition(0.3); |
|
383 | // pieSeries->setVerticalPosition(0.3); | |
384 | // m_chart->addSeries(pieSeries); |
|
384 | // m_chart->addSeries(pieSeries); | |
385 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
385 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
386 | // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); |
|
386 | // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); | |
387 |
|
387 | |||
388 | // // pie 3 |
|
388 | // // pie 3 | |
389 | // pieSeries = new QPieSeries; |
|
389 | // pieSeries = new QPieSeries; | |
390 | // pieSeries->setModel(m_model); |
|
390 | // pieSeries->setModel(m_model); | |
391 | // pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
391 | // pieSeries->setModelMapping(2,2, Qt::Vertical); | |
392 | // pieSeries->setLabelsVisible(true); |
|
392 | // pieSeries->setLabelsVisible(true); | |
393 | // pieSeries->setPieSize(0.35); |
|
393 | // pieSeries->setPieSize(0.35); | |
394 | // pieSeries->setHorizontalPosition(0.5); |
|
394 | // pieSeries->setHorizontalPosition(0.5); | |
395 | // pieSeries->setVerticalPosition(0.75); |
|
395 | // pieSeries->setVerticalPosition(0.75); | |
396 | // m_chart->addSeries(pieSeries); |
|
396 | // m_chart->addSeries(pieSeries); | |
397 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
397 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
398 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
398 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | |
399 |
|
399 | |||
400 | // // special pie |
|
400 | // // special pie | |
401 | // specialPie = new QPieSeries; |
|
401 | // specialPie = new QPieSeries; | |
402 | // specialPie->append(17, "1"); |
|
402 | // specialPie->append(17, "1"); | |
403 | // specialPie->append(45, "2"); |
|
403 | // specialPie->append(45, "2"); | |
404 | // specialPie->append(77, "3"); |
|
404 | // specialPie->append(77, "3"); | |
405 | // specialPie->append(37, "4"); |
|
405 | // specialPie->append(37, "4"); | |
406 | // specialPie->append(27, "5"); |
|
406 | // specialPie->append(27, "5"); | |
407 | // specialPie->append(47, "6"); |
|
407 | // specialPie->append(47, "6"); | |
408 | // specialPie->setPieSize(0.35); |
|
408 | // specialPie->setPieSize(0.35); | |
409 | // specialPie->setHorizontalPosition(0.8); |
|
409 | // specialPie->setHorizontalPosition(0.8); | |
410 | // specialPie->setVerticalPosition(0.75); |
|
410 | // specialPie->setVerticalPosition(0.75); | |
411 | // specialPie->setLabelsVisible(true); |
|
411 | // specialPie->setLabelsVisible(true); | |
412 | // m_chart->addSeries(specialPie); |
|
412 | // m_chart->addSeries(specialPie); | |
413 | } |
|
413 | } | |
414 | // else if (m_areaRadioButton->isChecked()) |
|
414 | // else if (m_areaRadioButton->isChecked()) | |
415 | // { |
|
415 | // { | |
416 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
416 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
417 |
|
417 | |||
418 | // QLineSeries* upperLineSeries = new QLineSeries; |
|
418 | // QLineSeries* upperLineSeries = new QLineSeries; | |
419 | // upperLineSeries->setModel(m_model); |
|
419 | // upperLineSeries->setModel(m_model); | |
420 | // upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
420 | // upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | |
421 | // // upperLineSeries->setModelMappingRange(1, 5); |
|
421 | // // upperLineSeries->setModelMappingRange(1, 5); | |
422 | // QLineSeries* lowerLineSeries = new QLineSeries; |
|
422 | // QLineSeries* lowerLineSeries = new QLineSeries; | |
423 | // lowerLineSeries->setModel(m_model); |
|
423 | // lowerLineSeries->setModel(m_model); | |
424 | // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
424 | // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); | |
425 | // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
425 | // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | |
426 | // m_chart->addSeries(areaSeries); |
|
426 | // m_chart->addSeries(areaSeries); | |
427 | // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
427 | // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); | |
428 | // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
428 | // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); | |
429 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
429 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
430 | // } |
|
430 | // } | |
431 | else if (m_barRadioButton->isChecked()) |
|
431 | else if (m_barRadioButton->isChecked()) | |
432 | { |
|
432 | { | |
433 | // m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
433 | // m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
434 |
|
434 | |||
435 | // QGroupedBarSeries* barSeries = new QGroupedBarSeries(); |
|
435 | // QGroupedBarSeries* barSeries = new QGroupedBarSeries(); | |
436 | // barSeries->setCategories(QStringList()); |
|
436 | // barSeries->setCategories(QStringList()); | |
437 | // barSeries->setModel(m_model); |
|
437 | // barSeries->setModel(m_model); | |
438 | // // barSeries->setModelMappingRange(2, 5); |
|
438 | // // barSeries->setModelMappingRange(2, 5); | |
439 | //// barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
439 | //// barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
440 |
|
440 | |||
441 | // QBarModelMapper *mapper = new QBarModelMapper; |
|
441 | // QBarModelMapper *mapper = new QBarModelMapper; | |
442 | // mapper->setMapCategories(5); |
|
442 | // mapper->setMapCategories(5); | |
443 | // mapper->setMapBarBottom(2); |
|
443 | // mapper->setMapBarBottom(2); | |
444 | // mapper->setMapBarTop(4); |
|
444 | // mapper->setMapBarTop(4); | |
445 | // barSeries->setModelMapper(mapper); |
|
445 | // barSeries->setModelMapper(mapper); | |
446 | // m_chart->addSeries(barSeries); |
|
446 | // m_chart->addSeries(barSeries); | |
447 | // QList<QBarSet*> barsets = barSeries->barSets(); |
|
447 | // QList<QBarSet*> barsets = barSeries->barSets(); | |
448 | // for (int i = 0; i < barsets.count(); i++) { |
|
448 | // for (int i = 0; i < barsets.count(); i++) { | |
449 | // seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
449 | // seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
450 | // m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
450 | // m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); | |
451 | // } |
|
451 | // } | |
452 | } |
|
452 | } | |
453 |
|
453 | |||
454 |
|
454 | |||
455 | if (!m_barRadioButton->isChecked()) { |
|
455 | if (!m_barRadioButton->isChecked()) { | |
456 | m_chart->axisX()->setRange(0, 500); |
|
456 | m_chart->axisX()->setRange(0, 500); | |
457 | m_chart->axisY()->setRange(0, 220); |
|
457 | m_chart->axisY()->setRange(0, 220); | |
458 | } |
|
458 | } | |
459 | m_chart->legend()->setVisible(true); |
|
459 | m_chart->legend()->setVisible(true); | |
460 |
|
460 | |||
461 | // repaint table view colors |
|
461 | // repaint table view colors | |
462 | m_tableView->repaint(); |
|
462 | m_tableView->repaint(); | |
463 | m_tableView->setFocus(); |
|
463 | m_tableView->setFocus(); | |
464 | } |
|
464 | } | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | void TableWidget::testPie() |
|
467 | void TableWidget::testPie() | |
468 | { |
|
468 | { | |
469 | // m_pieMapper->setCount(-1); |
|
469 | // m_pieMapper->setCount(-1); | |
470 | QPieSlice *slice = new QPieSlice("Hehe", 145); |
|
470 | QPieSlice *slice = new QPieSlice("Hehe", 145); | |
471 | slice->setLabelVisible(); |
|
471 | slice->setLabelVisible(); | |
472 | m_pieSeries->append(slice); |
|
472 | m_pieSeries->append(slice); | |
473 |
|
473 | |||
474 | slice = new QPieSlice("Hoho", 34); |
|
474 | slice = new QPieSlice("Hoho", 34); | |
475 | slice->setLabelVisible(); |
|
475 | slice->setLabelVisible(); | |
476 | m_pieSeries->append(slice); |
|
476 | m_pieSeries->append(slice); | |
477 | // m_series->modelMapper()->setMapX(4); |
|
477 | // m_series->modelMapper()->setMapX(4); | |
478 | // m_tableView->setColumnWidth(10, 250); |
|
478 | // m_tableView->setColumnWidth(10, 250); | |
479 | // if (specialPie) { |
|
479 | // if (specialPie) { | |
480 | // specialPie->remove(specialPie->slices().at(2)); |
|
480 | // specialPie->remove(specialPie->slices().at(2)); | |
481 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); |
|
481 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); | |
482 | // specialPie->append(4, "heloo"); |
|
482 | // specialPie->append(4, "heloo"); | |
483 | // } |
|
483 | // } | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | void TableWidget::testPie2() |
|
486 | void TableWidget::testPie2() | |
487 | { |
|
487 | { | |
488 | QPieSlice *slice; |
|
488 | QPieSlice *slice; | |
489 | if (m_pieSeries->count() > 0) { |
|
489 | if (m_pieSeries->count() > 0) { | |
490 | slice = m_pieSeries->slices().last(); |
|
490 | slice = m_pieSeries->slices().last(); | |
491 | m_pieSeries->remove(slice); |
|
491 | m_pieSeries->remove(slice); | |
492 | } |
|
492 | } | |
493 |
|
493 | |||
494 | if (m_pieSeries->count() > 0) { |
|
494 | if (m_pieSeries->count() > 0) { | |
495 | slice = m_pieSeries->slices().first(); |
|
495 | slice = m_pieSeries->slices().first(); | |
496 | m_pieSeries->remove(slice); |
|
496 | m_pieSeries->remove(slice); | |
497 | } |
|
497 | } | |
498 | } |
|
498 | } | |
499 |
|
499 | |||
500 | void TableWidget::testPie3() |
|
500 | void TableWidget::testPie3() | |
501 | { |
|
501 | { | |
502 | QPieSlice *slice; |
|
502 | QPieSlice *slice; | |
503 | if (m_pieSeries->count() > 0) { |
|
503 | if (m_pieSeries->count() > 0) { | |
504 | slice = m_pieSeries->slices().last(); |
|
504 | slice = m_pieSeries->slices().last(); | |
505 | slice->setLabel("Dalej"); |
|
505 | slice->setLabel("Dalej"); | |
506 | slice->setValue(222); |
|
506 | slice->setValue(222); | |
507 | } |
|
507 | } | |
508 |
|
508 | |||
509 | if (m_pieSeries->count() > 0) { |
|
509 | if (m_pieSeries->count() > 0) { | |
510 | slice = m_pieSeries->slices().first(); |
|
510 | slice = m_pieSeries->slices().first(); | |
511 | slice->setLabel("Prawie"); |
|
511 | slice->setLabel("Prawie"); | |
512 | slice->setValue(111); |
|
512 | slice->setValue(111); | |
513 | } |
|
513 | } | |
514 | } |
|
514 | } | |
515 |
|
515 | |||
516 | TableWidget::~TableWidget() |
|
516 | TableWidget::~TableWidget() | |
517 | { |
|
517 | { | |
518 |
|
518 | |||
519 | } |
|
519 | } |
General Comments 0
You need to be logged in to leave comments.
Login now