@@ -259,7 +259,7 QChart* ThemeWidget::createPieChart() const | |||
|
259 | 259 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
260 | 260 | QPieSeries *series = new QPieSeries(chart); |
|
261 | 261 | foreach (Data data, m_dataTable[i]) { |
|
262 |
QPieSlice *slice = series->append(data.first.y() |
|
|
262 | QPieSlice *slice = series->append(data.second, data.first.y()); | |
|
263 | 263 | if (data == m_dataTable[i].first()) { |
|
264 | 264 | slice->setLabelVisible(); |
|
265 | 265 | slice->setExploded(); |
@@ -22,8 +22,8 | |||
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
24 | 24 | |
|
25 |
CustomSlice::CustomSlice(qreal value |
|
|
26 |
:QPieSlice( |
|
|
25 | CustomSlice::CustomSlice(QString label, qreal value) | |
|
26 | :QPieSlice(label, value) | |
|
27 | 27 | { |
|
28 | 28 | connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool))); |
|
29 | 29 | } |
@@ -29,7 +29,7 class CustomSlice : public QPieSlice | |||
|
29 | 29 | Q_OBJECT |
|
30 | 30 | |
|
31 | 31 | public: |
|
32 |
CustomSlice(qreal value |
|
|
32 | CustomSlice(QString label, qreal value); | |
|
33 | 33 | |
|
34 | 34 | public: |
|
35 | 35 | QBrush originalBrush(); |
@@ -45,11 +45,11 MainWidget::MainWidget(QWidget* parent) | |||
|
45 | 45 | |
|
46 | 46 | // create series |
|
47 | 47 | m_series = new QPieSeries(); |
|
48 |
*m_series << new CustomSlice( |
|
|
49 |
*m_series << new CustomSlice( |
|
|
50 |
*m_series << new CustomSlice( |
|
|
51 |
*m_series << new CustomSlice( |
|
|
52 |
*m_series << new CustomSlice( |
|
|
48 | *m_series << new CustomSlice("Slice 1", 10.0); | |
|
49 | *m_series << new CustomSlice("Slice 2", 20.0); | |
|
50 | *m_series << new CustomSlice("Slice 3", 30.0); | |
|
51 | *m_series << new CustomSlice("Slice 4", 40.0); | |
|
52 | *m_series << new CustomSlice("Slice 5", 50.0); | |
|
53 | 53 | m_series->setLabelsVisible(); |
|
54 | 54 | chart->addSeries(m_series); |
|
55 | 55 | |
@@ -304,7 +304,7 void MainWidget::showFontDialog() | |||
|
304 | 304 | |
|
305 | 305 | void MainWidget::appendSlice() |
|
306 | 306 | { |
|
307 |
*m_series << new CustomSlice( |
|
|
307 | *m_series << new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0); | |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | void MainWidget::insertSlice() |
@@ -314,7 +314,7 void MainWidget::insertSlice() | |||
|
314 | 314 | |
|
315 | 315 | int i = m_series->slices().indexOf(m_slice); |
|
316 | 316 | |
|
317 |
m_series->insert(i, new CustomSlice( |
|
|
317 | m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0)); | |
|
318 | 318 | } |
|
319 | 319 | |
|
320 | 320 | void MainWidget::removeSlice() |
@@ -32,11 +32,11 int main(int argc, char *argv[]) | |||
|
32 | 32 | |
|
33 | 33 | //![1] |
|
34 | 34 | QPieSeries *series = new QPieSeries(); |
|
35 |
series->append( |
|
|
36 |
series->append( |
|
|
37 |
series->append( |
|
|
38 |
series->append( |
|
|
39 |
series->append( |
|
|
35 | series->append("Jane", 1); | |
|
36 | series->append("Joe", 2); | |
|
37 | series->append("Andy", 3); | |
|
38 | series->append("Barbara", 4); | |
|
39 | series->append("Axel", 5); | |
|
40 | 40 | //![1] |
|
41 | 41 | |
|
42 | 42 | //![2] |
@@ -81,7 +81,7 QPieSlice* DeclarativePieSeries::find(QString label) | |||
|
81 | 81 | QPieSlice* DeclarativePieSeries::append(QString name, qreal value) |
|
82 | 82 | { |
|
83 | 83 | // TODO: parameter order is wrong, switch it: |
|
84 |
return QPieSeries::append( |
|
|
84 | return QPieSeries::append(name, value); | |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model) |
@@ -191,12 +191,12 QPieSeries& QPieSeries::operator << (QPieSlice* slice) | |||
|
191 | 191 | |
|
192 | 192 | |
|
193 | 193 | /*! |
|
194 |
Appends a single slice to the series with give \a value and \a |
|
|
194 | Appends a single slice to the series with give \a value and \a label. | |
|
195 | 195 | Slice ownership is passed to the series. |
|
196 | 196 | */ |
|
197 |
QPieSlice* QPieSeries::append(qreal value |
|
|
197 | QPieSlice* QPieSeries::append(QString label, qreal value) | |
|
198 | 198 | { |
|
199 |
QPieSlice* slice = new QPieSlice( |
|
|
199 | QPieSlice* slice = new QPieSlice(label, value); | |
|
200 | 200 | append(slice); |
|
201 | 201 | return slice; |
|
202 | 202 | } |
@@ -737,7 +737,7 void QPieSeriesPrivate::initializePieFromModel() | |||
|
737 | 737 | else |
|
738 | 738 | sliceCount = qMin(m_mapper->count(), m_model->rowCount() - m_mapper->first()); |
|
739 | 739 | for (int i = m_mapper->first(); i < m_mapper->first() + sliceCount; i++) |
|
740 | q->append(m_model->data(m_model->index(i, m_mapper->mapValues()), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, m_mapper->mapLabels()), Qt::DisplayRole).toString()); | |
|
740 | q->append(m_model->data(m_model->index(i, m_mapper->mapLabels()), Qt::DisplayRole).toString(), m_model->data(m_model->index(i, m_mapper->mapValues()), Qt::DisplayRole).toDouble()); | |
|
741 | 741 | } else { |
|
742 | 742 | if (m_mapper->mapValues() >= m_model->rowCount() || m_mapper->mapLabels() >= m_model->rowCount()) |
|
743 | 743 | return; // mapped columns are not existing |
@@ -748,7 +748,7 void QPieSeriesPrivate::initializePieFromModel() | |||
|
748 | 748 | else |
|
749 | 749 | sliceCount = qMin(m_mapper->count(), m_model->columnCount() - m_mapper->first()); |
|
750 | 750 | for (int i = m_mapper->first(); i < m_mapper->first() + sliceCount; i++) |
|
751 | q->append(m_model->data(m_model->index(m_mapper->mapValues(), i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(m_mapper->mapLabels(), i), Qt::DisplayRole).toString()); | |
|
751 | q->append(m_model->data(m_model->index(m_mapper->mapLabels(), i), Qt::DisplayRole).toString(), m_model->data(m_model->index(m_mapper->mapValues(), i), Qt::DisplayRole).toDouble()); | |
|
752 | 752 | } |
|
753 | 753 | q->setLabelsVisible(true); |
|
754 | 754 | } |
@@ -48,7 +48,7 public: | |||
|
48 | 48 | bool append(QPieSlice* slice); |
|
49 | 49 | bool append(QList<QPieSlice*> slices); |
|
50 | 50 | QPieSeries& operator << (QPieSlice* slice); |
|
51 |
QPieSlice* append(qreal value |
|
|
51 | QPieSlice* append(QString label, qreal value); | |
|
52 | 52 | bool insert(int index, QPieSlice* slice); |
|
53 | 53 | bool remove(QPieSlice* slice); |
|
54 | 54 | void clear(); |
@@ -68,7 +68,7 QPieSlice::QPieSlice(QObject *parent) | |||
|
68 | 68 | Constructs an empty slice with given \a value, \a label and a \a parent. |
|
69 | 69 | \sa QPieSeries::append(), QPieSeries::insert() |
|
70 | 70 | */ |
|
71 |
QPieSlice::QPieSlice(qreal value |
|
|
71 | QPieSlice::QPieSlice(QString label, qreal value, QObject *parent) | |
|
72 | 72 | :QObject(parent), |
|
73 | 73 | d(new PieSliceData()) |
|
74 | 74 | { |
@@ -39,7 +39,7 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject | |||
|
39 | 39 | |
|
40 | 40 | public: |
|
41 | 41 | explicit QPieSlice(QObject *parent = 0); |
|
42 |
QPieSlice(qreal value |
|
|
42 | QPieSlice(QString label, qreal value, QObject *parent = 0); | |
|
43 | 43 | virtual ~QPieSlice(); |
|
44 | 44 | |
|
45 | 45 | void setValue(qreal value); |
@@ -101,7 +101,7 void tst_qpieseries::append() | |||
|
101 | 101 | // append pointer |
|
102 | 102 | QPieSlice *slice1 = 0; |
|
103 | 103 | QVERIFY(!s.append(slice1)); |
|
104 |
slice1 = new QPieSlice( |
|
|
104 | slice1 = new QPieSlice("slice 1", 1); | |
|
105 | 105 | QVERIFY(s.append(slice1)); |
|
106 | 106 | QVERIFY(!s.append(slice1)); |
|
107 | 107 | QCOMPARE(s.count(), 1); |
@@ -112,19 +112,19 void tst_qpieseries::append() | |||
|
112 | 112 | list << (QPieSlice *) 0; |
|
113 | 113 | QVERIFY(!s.append(list)); |
|
114 | 114 | list.clear(); |
|
115 |
list << new QPieSlice( |
|
|
116 |
list << new QPieSlice( |
|
|
115 | list << new QPieSlice("slice 2", 2); | |
|
116 | list << new QPieSlice("slice 3", 3); | |
|
117 | 117 | QVERIFY(s.append(list)); |
|
118 | 118 | QVERIFY(!s.append(list)); |
|
119 | 119 | QCOMPARE(s.count(), 3); |
|
120 | 120 | |
|
121 | 121 | // append operator |
|
122 |
s << new QPieSlice( |
|
|
122 | s << new QPieSlice("slice 4", 4); | |
|
123 | 123 | s << slice1; // fails because already added |
|
124 | 124 | QCOMPARE(s.count(), 4); |
|
125 | 125 | |
|
126 | 126 | // append with params |
|
127 |
QPieSlice *slice5 = s.append( |
|
|
127 | QPieSlice *slice5 = s.append("slice 5", 5); | |
|
128 | 128 | QVERIFY(slice5 != 0); |
|
129 | 129 | QCOMPARE(slice5->value(), 5.0); |
|
130 | 130 | QCOMPARE(slice5->label(), QString("slice 5")); |
@@ -145,7 +145,7 void tst_qpieseries::insert() | |||
|
145 | 145 | // insert one slice |
|
146 | 146 | QPieSlice *slice1 = 0; |
|
147 | 147 | QVERIFY(!s.insert(0, slice1)); |
|
148 |
slice1 = new QPieSlice( |
|
|
148 | slice1 = new QPieSlice("slice 1", 1); | |
|
149 | 149 | QVERIFY(!s.insert(-1, slice1)); |
|
150 | 150 | QVERIFY(!s.insert(5, slice1)); |
|
151 | 151 | QVERIFY(s.insert(0, slice1)); |
@@ -153,12 +153,12 void tst_qpieseries::insert() | |||
|
153 | 153 | QCOMPARE(s.count(), 1); |
|
154 | 154 | |
|
155 | 155 | // add some more slices |
|
156 |
s.append( |
|
|
157 |
s.append( |
|
|
156 | s.append("slice 2", 2); | |
|
157 | s.append("slice 4", 4); | |
|
158 | 158 | QCOMPARE(s.count(), 3); |
|
159 | 159 | |
|
160 | 160 | // insert between slices |
|
161 |
s.insert(2, new QPieSlice( |
|
|
161 | s.insert(2, new QPieSlice("slice 3", 3)); | |
|
162 | 162 | QCOMPARE(s.count(), 4); |
|
163 | 163 | |
|
164 | 164 | // check slices |
@@ -173,9 +173,9 void tst_qpieseries::remove() | |||
|
173 | 173 | QPieSeries s; |
|
174 | 174 | |
|
175 | 175 | // add some slices |
|
176 |
QPieSlice *slice1 = s.append( |
|
|
177 |
QPieSlice *slice2 = s.append( |
|
|
178 |
QPieSlice *slice3 = s.append( |
|
|
176 | QPieSlice *slice1 = s.append("slice 1", 1); | |
|
177 | QPieSlice *slice2 = s.append("slice 2", 2); | |
|
178 | QPieSlice *slice3 = s.append("slice 3", 3); | |
|
179 | 179 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); |
|
180 | 180 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); |
|
181 | 181 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); |
@@ -208,15 +208,15 void tst_qpieseries::calculatedValues() | |||
|
208 | 208 | QPieSeries s; |
|
209 | 209 | |
|
210 | 210 | // add a slice |
|
211 |
QPieSlice *slice1 = s.append( |
|
|
211 | QPieSlice *slice1 = s.append("slice 1", 1); | |
|
212 | 212 | verifyCalculatedData(s, &ok); |
|
213 | 213 | if (!ok) |
|
214 | 214 | return; |
|
215 | 215 | |
|
216 | 216 | // add some more slices |
|
217 | 217 | QList<QPieSlice *> list; |
|
218 |
list << new QPieSlice( |
|
|
219 |
list << new QPieSlice( |
|
|
218 | list << new QPieSlice("slice 2", 2); | |
|
219 | list << new QPieSlice("slice 3", 3); | |
|
220 | 220 | s.append(list); |
|
221 | 221 | verifyCalculatedData(s, &ok); |
|
222 | 222 | if (!ok) |
@@ -229,7 +229,7 void tst_qpieseries::calculatedValues() | |||
|
229 | 229 | return; |
|
230 | 230 | |
|
231 | 231 | // insert a slice |
|
232 |
s.insert(0, new QPieSlice( |
|
|
232 | s.insert(0, new QPieSlice("Slice 4", 4)); | |
|
233 | 233 | verifyCalculatedData(s, &ok); |
|
234 | 234 | if (!ok) |
|
235 | 235 | return; |
@@ -271,9 +271,9 void tst_qpieseries::clickedSignal() | |||
|
271 | 271 | // create a pie series |
|
272 | 272 | QPieSeries *series = new QPieSeries(); |
|
273 | 273 | series->setPieSize(1.0); |
|
274 |
QPieSlice *s1 = series->append( |
|
|
275 |
series->append( |
|
|
276 |
series->append( |
|
|
274 | QPieSlice *s1 = series->append("slice 1", 1); | |
|
275 | series->append("slice 2", 2); | |
|
276 | series->append("slice 3", 3); | |
|
277 | 277 | QSignalSpy clickSpy1(series, SIGNAL(clicked(QPieSlice*))); |
|
278 | 278 | |
|
279 | 279 | // add series to the chart |
@@ -296,9 +296,9 void tst_qpieseries::hoverSignal() | |||
|
296 | 296 | // create a pie series |
|
297 | 297 | QPieSeries *series = new QPieSeries(); |
|
298 | 298 | series->setPieSize(1.0); |
|
299 |
QPieSlice *s1 = series->append( |
|
|
300 |
series->append( |
|
|
301 |
series->append( |
|
|
299 | QPieSlice *s1 = series->append("slice 1", 1); | |
|
300 | series->append("slice 2", 2); | |
|
301 | series->append("slice 3", 3); | |
|
302 | 302 | |
|
303 | 303 | // add series to the chart |
|
304 | 304 | QChartView view(new QChart()); |
@@ -88,7 +88,7 void tst_qpieslice::construction() | |||
|
88 | 88 | QCOMPARE(slice1.endAngle(), 0.0); |
|
89 | 89 | |
|
90 | 90 | // value and label params |
|
91 |
QPieSlice slice2( |
|
|
91 | QPieSlice slice2("foobar", 1.0); | |
|
92 | 92 | QCOMPARE(slice2.value(), 1.0); |
|
93 | 93 | QCOMPARE(slice2.label(), QString("foobar")); |
|
94 | 94 | QVERIFY(!slice2.isLabelVisible()); |
@@ -136,9 +136,9 void tst_qpieslice::customize() | |||
|
136 | 136 | { |
|
137 | 137 | // create a pie series |
|
138 | 138 | QPieSeries *series = new QPieSeries(); |
|
139 |
QPieSlice *s1 = series->append( |
|
|
140 |
QPieSlice *s2 = series->append( |
|
|
141 |
series->append( |
|
|
139 | QPieSlice *s1 = series->append("slice 1", 1); | |
|
140 | QPieSlice *s2 = series->append("slice 2", 2); | |
|
141 | series->append("slice 3", 3); | |
|
142 | 142 | |
|
143 | 143 | // customize a slice |
|
144 | 144 | QPen p1(Qt::red); |
@@ -171,14 +171,14 void tst_qpieslice::customize() | |||
|
171 | 171 | QCOMPARE(s1->labelFont(), f1); |
|
172 | 172 | |
|
173 | 173 | // add a slice |
|
174 |
series->append( |
|
|
174 | series->append("slice 4", 4); | |
|
175 | 175 | QCOMPARE(s1->pen(), p1); |
|
176 | 176 | QCOMPARE(s1->brush(), b1); |
|
177 | 177 | QCOMPARE(s1->labelPen(), p1); |
|
178 | 178 | QCOMPARE(s1->labelFont(), f1); |
|
179 | 179 | |
|
180 | 180 | // insert a slice |
|
181 |
series->insert(0, new QPieSlice( |
|
|
181 | series->insert(0, new QPieSlice("slice 5", 5)); | |
|
182 | 182 | QCOMPARE(s1->pen(), p1); |
|
183 | 183 | QCOMPARE(s1->brush(), b1); |
|
184 | 184 | QCOMPARE(s1->labelPen(), p1); |
@@ -198,9 +198,9 void tst_qpieslice::mouseClick() | |||
|
198 | 198 | // create a pie series |
|
199 | 199 | QPieSeries *series = new QPieSeries(); |
|
200 | 200 | series->setPieSize(1.0); |
|
201 |
QPieSlice *s1 = series->append( |
|
|
202 |
QPieSlice *s2 = series->append( |
|
|
203 |
QPieSlice *s3 = series->append( |
|
|
201 | QPieSlice *s1 = series->append("slice 1", 1); | |
|
202 | QPieSlice *s2 = series->append("slice 2", 2); | |
|
203 | QPieSlice *s3 = series->append("slice 3", 3); | |
|
204 | 204 | QSignalSpy clickSpy1(s1, SIGNAL(clicked())); |
|
205 | 205 | QSignalSpy clickSpy2(s2, SIGNAL(clicked())); |
|
206 | 206 | QSignalSpy clickSpy3(s3, SIGNAL(clicked())); |
@@ -231,9 +231,9 void tst_qpieslice::mouseHover() | |||
|
231 | 231 | // create a pie series |
|
232 | 232 | QPieSeries *series = new QPieSeries(); |
|
233 | 233 | series->setPieSize(1.0); |
|
234 |
QPieSlice *s1 = series->append( |
|
|
235 |
series->append( |
|
|
236 |
series->append( |
|
|
234 | QPieSlice *s1 = series->append("slice 1", 1); | |
|
235 | series->append("slice 2", 2); | |
|
236 | series->append("slice 3", 3); | |
|
237 | 237 | |
|
238 | 238 | // add series to the chart |
|
239 | 239 | QChartView view(new QChart()); |
@@ -261,7 +261,7 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS | |||
|
261 | 261 | QPieSeries *series = new QPieSeries(); |
|
262 | 262 | QList<qreal> column = data.at(j); |
|
263 | 263 | for (int i(0); i < column.count(); i++) |
|
264 |
series->append( |
|
|
264 | series->append(labels.at(i), column.at(i)); | |
|
265 | 265 | m_chart->addSeries(series); |
|
266 | 266 | } |
|
267 | 267 | } else if (seriesName == "Bar" |
General Comments 0
You need to be logged in to leave comments.
Login now