##// END OF EJS Templates
API review changes for pie
Jani Honkonen -
r1009:983f422506c5
parent child
Show More
@@ -25,8 +25,7 QTCOMMERCIALCHART_USE_NAMESPACE
25 CustomSlice::CustomSlice(qreal value, QString label)
25 CustomSlice::CustomSlice(qreal value, QString label)
26 :QPieSlice(value, label)
26 :QPieSlice(value, label)
27 {
27 {
28 connect(this, SIGNAL(hoverEnter()), this, SLOT(handleHoverEnter()));
28 connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool)));
29 connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave()));
30 }
29 }
31
30
32 QBrush CustomSlice::originalBrush()
31 QBrush CustomSlice::originalBrush()
@@ -34,17 +33,16 QBrush CustomSlice::originalBrush()
34 return m_originalBrush;
33 return m_originalBrush;
35 }
34 }
36
35
37 void CustomSlice::handleHoverEnter()
36 void CustomSlice::showHighlight(bool show)
38 {
37 {
39 QBrush brush = this->brush();
38 if (show) {
40 m_originalBrush = brush;
39 QBrush brush = this->brush();
41 brush.setColor(brush.color().lighter());
40 m_originalBrush = brush;
42 setBrush(brush);
41 brush.setColor(brush.color().lighter());
43 }
42 setBrush(brush);
44
43 } else {
45 void CustomSlice::handleHoverLeave()
44 setBrush(m_originalBrush);
46 {
45 }
47 setBrush(m_originalBrush);
48 }
46 }
49
47
50 #include "moc_customslice.cpp"
48 #include "moc_customslice.cpp"
@@ -35,8 +35,7 public:
35 QBrush originalBrush();
35 QBrush originalBrush();
36
36
37 public Q_SLOTS:
37 public Q_SLOTS:
38 void handleHoverEnter();
38 void showHighlight(bool show);
39 void handleHoverLeave();
40
39
41 private:
40 private:
42 QBrush m_originalBrush;
41 QBrush m_originalBrush;
@@ -53,7 +53,7 MainWidget::MainWidget(QWidget* parent)
53 m_series->setLabelsVisible();
53 m_series->setLabelsVisible();
54 chart->addSeries(m_series);
54 chart->addSeries(m_series);
55
55
56 connect(m_series, SIGNAL(clicked(QPieSlice*,Qt::MouseButtons)), this, SLOT(handleSliceClicked(QPieSlice*,Qt::MouseButtons)));
56 connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*)));
57
57
58 // chart settings
58 // chart settings
59 m_themeComboBox = new QComboBox();
59 m_themeComboBox = new QComboBox();
@@ -69,16 +69,20 MainWidget::MainWidget(QWidget* parent)
69 m_animationsCheckBox = new QCheckBox();
69 m_animationsCheckBox = new QCheckBox();
70 m_animationsCheckBox->setCheckState(Qt::Checked);
70 m_animationsCheckBox->setCheckState(Qt::Checked);
71
71
72 m_legendCheckBox = new QCheckBox();
73
72 QFormLayout* chartSettingsLayout = new QFormLayout();
74 QFormLayout* chartSettingsLayout = new QFormLayout();
73 chartSettingsLayout->addRow("Theme", m_themeComboBox);
75 chartSettingsLayout->addRow("Theme", m_themeComboBox);
74 chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox);
76 chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox);
75 chartSettingsLayout->addRow("Animations", m_animationsCheckBox);
77 chartSettingsLayout->addRow("Animations", m_animationsCheckBox);
78 chartSettingsLayout->addRow("Legend", m_legendCheckBox);
76 QGroupBox* chartSettings = new QGroupBox("Chart");
79 QGroupBox* chartSettings = new QGroupBox("Chart");
77 chartSettings->setLayout(chartSettingsLayout);
80 chartSettings->setLayout(chartSettingsLayout);
78
81
79 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings()));
82 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings()));
80 connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
83 connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
81 connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
84 connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
85 connect(m_legendCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
82
86
83 // series settings
87 // series settings
84 m_hPosition = new QDoubleSpinBox();
88 m_hPosition = new QDoubleSpinBox();
@@ -211,6 +215,11 void MainWidget::updateChartSettings()
211 m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
215 m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
212 else
216 else
213 m_chartView->chart()->setAnimationOptions(QChart::NoAnimation);
217 m_chartView->chart()->setAnimationOptions(QChart::NoAnimation);
218
219 if (m_legendCheckBox->checkState() == Qt::Checked)
220 m_chartView->chart()->legend()->show();
221 else
222 m_chartView->chart()->legend()->hide();
214 }
223 }
215
224
216 void MainWidget::updateSerieSettings()
225 void MainWidget::updateSerieSettings()
@@ -240,10 +249,8 void MainWidget::updateSliceSettings()
240 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
249 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
241 }
250 }
242
251
243 void MainWidget::handleSliceClicked(QPieSlice* slice, Qt::MouseButtons buttons)
252 void MainWidget::handleSliceClicked(QPieSlice* slice)
244 {
253 {
245 Q_UNUSED(buttons);
246
247 m_slice = static_cast<CustomSlice*>(slice);
254 m_slice = static_cast<CustomSlice*>(slice);
248
255
249 // name
256 // name
@@ -51,7 +51,7 public Q_SLOTS:
51 void updateChartSettings();
51 void updateChartSettings();
52 void updateSerieSettings();
52 void updateSerieSettings();
53 void updateSliceSettings();
53 void updateSliceSettings();
54 void handleSliceClicked(QPieSlice* slice, Qt::MouseButtons buttons);
54 void handleSliceClicked(QPieSlice* slice);
55 void showFontDialog();
55 void showFontDialog();
56 void appendSlice();
56 void appendSlice();
57 void insertSlice();
57 void insertSlice();
@@ -61,6 +61,7 private:
61 QComboBox *m_themeComboBox;
61 QComboBox *m_themeComboBox;
62 QCheckBox *m_aaCheckBox;
62 QCheckBox *m_aaCheckBox;
63 QCheckBox *m_animationsCheckBox;
63 QCheckBox *m_animationsCheckBox;
64 QCheckBox *m_legendCheckBox;
64
65
65 QChartView* m_chartView;
66 QChartView* m_chartView;
66 QPieSeries* m_series;
67 QPieSeries* m_series;
@@ -30,8 +30,7 DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QAbstractSeries* dri
30 updateLabel();
30 updateLabel();
31 setLabelFont(QFont("Arial", 8));
31 setLabelFont(QFont("Arial", 8));
32 connect(this, SIGNAL(changed()), this, SLOT(updateLabel()));
32 connect(this, SIGNAL(changed()), this, SLOT(updateLabel()));
33 connect(this, SIGNAL(hoverEnter()), this, SLOT(showHighlight()));
33 connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool)));
34 connect(this, SIGNAL(hoverLeave()), this, SLOT(hideHighlight()));
35 }
34 }
36
35
37 DrilldownSlice::~DrilldownSlice()
36 DrilldownSlice::~DrilldownSlice()
@@ -55,16 +54,10 void DrilldownSlice::updateLabel()
55 setLabel(label);
54 setLabel(label);
56 }
55 }
57
56
58 void DrilldownSlice::showHighlight()
57 void DrilldownSlice::showHighlight(bool show)
59 {
58 {
60 setExploded();
59 setExploded(show);
61 setLabelVisible();
60 setLabelVisible(show);
62 }
63
64 void DrilldownSlice::hideHighlight()
65 {
66 setExploded(false);
67 setLabelVisible(false);
68 }
61 }
69
62
70 #include "moc_drilldownslice.cpp"
63 #include "moc_drilldownslice.cpp"
@@ -39,8 +39,7 public:
39
39
40 public Q_SLOTS:
40 public Q_SLOTS:
41 void updateLabel();
41 void updateLabel();
42 void showHighlight();
42 void showHighlight(bool show);
43 void hideHighlight();
44
43
45 private:
44 private:
46 QAbstractSeries* m_drilldownSeries;
45 QAbstractSeries* m_drilldownSeries;
@@ -58,12 +58,12 int main(int argc, char *argv[])
58 foreach (QString month, months)
58 foreach (QString month, months)
59 *series << new DrilldownSlice(qrand() % 1000, month, yearSeries);
59 *series << new DrilldownSlice(qrand() % 1000, month, yearSeries);
60
60
61 QObject::connect(series, SIGNAL(clicked(QPieSlice*,Qt::MouseButtons)), chart, SLOT(handleSliceClicked(QPieSlice*)));
61 QObject::connect(series, SIGNAL(clicked(QPieSlice*)), chart, SLOT(handleSliceClicked(QPieSlice*)));
62
62
63 *yearSeries << new DrilldownSlice(series->sum(), name, series);
63 *yearSeries << new DrilldownSlice(series->sum(), name, series);
64 }
64 }
65
65
66 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*,Qt::MouseButtons)), chart, SLOT(handleSliceClicked(QPieSlice*)));
66 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*)), chart, SLOT(handleSliceClicked(QPieSlice*)));
67
67
68 chart->changeSeries(yearSeries);
68 chart->changeSeries(yearSeries);
69
69
@@ -154,7 +154,7 void BarLegendMarker::updated()
154 PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend),
154 PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend),
155 m_pieslice(pieslice)
155 m_pieslice(pieslice)
156 {
156 {
157 QObject::connect(this, SIGNAL(selected()),pieslice, SIGNAL(selected()));
157 QObject::connect(this, SIGNAL(selected()),pieslice, SIGNAL(clicked()));
158 QObject::connect(pieslice, SIGNAL(changed()), this, SLOT(updated()));
158 QObject::connect(pieslice, SIGNAL(changed()), this, SLOT(updated()));
159 updated();
159 updated();
160 }
160 }
@@ -35,6 +35,7
35 #include "qpercentbarseries.h"
35 #include "qpercentbarseries.h"
36 #include "qbarset.h"
36 #include "qbarset.h"
37 #include "qpieseries.h"
37 #include "qpieseries.h"
38 #include "qpieseries_p.h"
38 #include "qpieslice.h"
39 #include "qpieslice.h"
39 #include "chartpresenter_p.h"
40 #include "chartpresenter_p.h"
40 #include <QPainter>
41 #include <QPainter>
@@ -416,8 +417,9 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
416 if(series->type() == QAbstractSeries::SeriesTypePie)
417 if(series->type() == QAbstractSeries::SeriesTypePie)
417 {
418 {
418 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
419 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
419 QObject::connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleUpdateSeries()));
420 QPieSeriesPrivate *d = QPieSeriesPrivate::seriesData(*pieSeries);
420 QObject::connect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleUpdateSeries()));
421 QObject::connect(d, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
422 QObject::connect(d, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
421 }
423 }
422
424
423 updateLayout();
425 updateLayout();
@@ -438,20 +440,21 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
438 if(series->type() == QAbstractSeries::SeriesTypePie)
440 if(series->type() == QAbstractSeries::SeriesTypePie)
439 {
441 {
440 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
442 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
441 QObject::disconnect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleUpdateSeries()));
443 QPieSeriesPrivate *d = QPieSeriesPrivate::seriesData(*pieSeries);
442 QObject::disconnect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleUpdateSeries()));
444 QObject::disconnect(d, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
445 QObject::disconnect(d, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
443 }
446 }
444
447
445 updateLayout();
448 updateLayout();
446 }
449 }
447
450
448 void QLegendPrivate::handleUpdateSeries()
451 void QLegendPrivate::handleUpdatePieSeries()
449 {
452 {
450 //TODO: reimplement to be optimal
453 //TODO: reimplement to be optimal
451 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
454 QPieSeriesPrivate* d = qobject_cast<QPieSeriesPrivate *> (sender());
452 Q_ASSERT(series);
455 Q_ASSERT(d->q_func());
453 handleSeriesRemoved(series);
456 handleSeriesRemoved(d->q_func());
454 handleSeriesAdded(series,0);
457 handleSeriesAdded(d->q_func(), 0);
455 }
458 }
456
459
457 #include "moc_qlegend.cpp"
460 #include "moc_qlegend.cpp"
@@ -50,7 +50,7 public:
50 public Q_SLOTS:
50 public Q_SLOTS:
51 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
51 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
52 void handleSeriesRemoved(QAbstractSeries *series);
52 void handleSeriesRemoved(QAbstractSeries *series);
53 void handleUpdateSeries(); //TODO remove this function
53 void handleUpdatePieSeries(); //TODO remove this function
54
54
55 private:
55 private:
56 QLegend *q_ptr;
56 QLegend *q_ptr;
@@ -22,6 +22,7
22 #include "piesliceitem_p.h"
22 #include "piesliceitem_p.h"
23 #include "qpieslice.h"
23 #include "qpieslice.h"
24 #include "qpieseries.h"
24 #include "qpieseries.h"
25 #include "qpieseries_p.h"
25 #include "chartpresenter_p.h"
26 #include "chartpresenter_p.h"
26 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
27 #include "chartanimator_p.h"
28 #include "chartanimator_p.h"
@@ -35,10 +36,12 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter)
35 m_series(series)
36 m_series(series)
36 {
37 {
37 Q_ASSERT(series);
38 Q_ASSERT(series);
38 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
39
39 connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
40 QPieSeriesPrivate *d = QPieSeriesPrivate::seriesData(*series);
40 connect(series, SIGNAL(piePositionChanged()), this, SLOT(handlePieLayoutChanged()));
41 connect(d, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
41 connect(series, SIGNAL(pieSizeChanged()), this, SLOT(handlePieLayoutChanged()));
42 connect(d, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
43 connect(d, SIGNAL(piePositionChanged()), this, SLOT(handlePieLayoutChanged()));
44 connect(d, SIGNAL(pieSizeChanged()), this, SLOT(handlePieLayoutChanged()));
42
45
43 QTimer::singleShot(0, this, SLOT(initialize())); // TODO: get rid of this
46 QTimer::singleShot(0, this, SLOT(initialize())); // TODO: get rid of this
44
47
@@ -75,9 +78,8 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
75 PieSliceItem* item = new PieSliceItem(this);
78 PieSliceItem* item = new PieSliceItem(this);
76 m_slices.insert(s, item);
79 m_slices.insert(s, item);
77 connect(s, SIGNAL(changed()), this, SLOT(handleSliceChanged()));
80 connect(s, SIGNAL(changed()), this, SLOT(handleSliceChanged()));
78 connect(item, SIGNAL(clicked(Qt::MouseButtons)), s, SIGNAL(clicked(Qt::MouseButtons)));
81 connect(item, SIGNAL(clicked(Qt::MouseButtons)), s, SIGNAL(clicked()));
79 connect(item, SIGNAL(hoverEnter()), s, SIGNAL(hoverEnter()));
82 connect(item, SIGNAL(hovered(bool)), s, SIGNAL(hovered(bool)));
80 connect(item, SIGNAL(hoverLeave()), s, SIGNAL(hoverLeave()));
81
83
82 PieSliceData data = sliceData(s);
84 PieSliceData data = sliceData(s);
83
85
@@ -85,12 +85,12 void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*op
85
85
86 void PieSliceItem::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/)
86 void PieSliceItem::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/)
87 {
87 {
88 emit hoverEnter(); // TODO: refactor emit hover(somebooleanvalue)
88 emit hovered(true);
89 }
89 }
90
90
91 void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
91 void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
92 {
92 {
93 emit hoverLeave(); // TODO: refactor emit hover(somebooleanvalue)
93 emit hovered(false);
94 }
94 }
95
95
96 void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
96 void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
@@ -55,8 +55,7 public: // from QGraphicsItem
55
55
56 Q_SIGNALS:
56 Q_SIGNALS:
57 void clicked(Qt::MouseButtons buttons);
57 void clicked(Qt::MouseButtons buttons);
58 void hoverEnter();
58 void hovered(bool state);
59 void hoverLeave();
60
59
61 public:
60 public:
62 void setSliceData(PieSliceData sliceData);
61 void setSliceData(PieSliceData sliceData);
@@ -162,12 +162,11 void QPieSeries::append(QList<QPieSlice*> slices)
162
162
163 foreach (QPieSlice* s, slices) {
163 foreach (QPieSlice* s, slices) {
164 connect(s, SIGNAL(changed()), d, SLOT(sliceChanged()));
164 connect(s, SIGNAL(changed()), d, SLOT(sliceChanged()));
165 connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons)));
165 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
166 connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
166 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
167 connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
168 }
167 }
169
168
170 emit added(slices);
169 emit d->added(slices);
171 }
170 }
172
171
173 /*!
172 /*!
@@ -215,11 +214,10 void QPieSeries::insert(int index, QPieSlice* slice)
215 d->updateDerivativeData();
214 d->updateDerivativeData();
216
215
217 connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged()));
216 connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged()));
218 connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons)));
217 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
219 connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
218 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
220 connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
221
219
222 emit added(QList<QPieSlice*>() << slice);
220 emit d->added(QList<QPieSlice*>() << slice);
223 }
221 }
224
222
225 /*!
223 /*!
@@ -237,7 +235,7 void QPieSeries::remove(QPieSlice* slice)
237
235
238 d->updateDerivativeData();
236 d->updateDerivativeData();
239
237
240 emit removed(QList<QPieSlice*>() << slice);
238 emit d->removed(QList<QPieSlice*>() << slice);
241
239
242 delete slice;
240 delete slice;
243 slice = 0;
241 slice = 0;
@@ -260,7 +258,7 void QPieSeries::clear()
260
258
261 d->updateDerivativeData();
259 d->updateDerivativeData();
262
260
263 emit removed(slices);
261 emit d->removed(slices);
264 }
262 }
265
263
266 /*!
264 /*!
@@ -294,14 +292,14 void QPieSeries::setHorizontalPosition(qreal relativePosition)
294 {
292 {
295 Q_D(QPieSeries);
293 Q_D(QPieSeries);
296 if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0))
294 if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0))
297 emit piePositionChanged();
295 emit d->piePositionChanged();
298 }
296 }
299
297
300 void QPieSeries::setVerticalPosition(qreal relativePosition)
298 void QPieSeries::setVerticalPosition(qreal relativePosition)
301 {
299 {
302 Q_D(QPieSeries);
300 Q_D(QPieSeries);
303 if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0))
301 if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0))
304 emit piePositionChanged();
302 emit d->piePositionChanged();
305 }
303 }
306
304
307 qreal QPieSeries::horizontalPosition() const
305 qreal QPieSeries::horizontalPosition() const
@@ -320,7 +318,7 void QPieSeries::setPieSize(qreal relativeSize)
320 {
318 {
321 Q_D(QPieSeries);
319 Q_D(QPieSeries);
322 if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0))
320 if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0))
323 emit pieSizeChanged();
321 emit d->pieSizeChanged();
324 }
322 }
325
323
326 qreal QPieSeries::pieSize() const
324 qreal QPieSeries::pieSize() const
@@ -397,59 +395,21 qreal QPieSeries::sum() const
397 }
395 }
398
396
399 /*!
397 /*!
400 \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons)
398 \fn void QPieSeries::clicked(QPieSlice* slice)
401
399
402 This signal is emitted when a \a slice has been clicked with mouse \a buttons.
400 This signal is emitted when a \a slice has been clicked.
403
401
404 \sa QPieSlice::clicked()
402 \sa QPieSlice::clicked()
405 */
403 */
406
404
407 /*!
405 /*!
408 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
406 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
409
407
410 This signal is emitted when user has hovered over a \a slice.
408 This signal is emitted when user has hovered over or away from the \a slice.
411
409
412 \sa QPieSlice::hoverEnter()
410 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
413 */
414
415 /*!
416 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
417
418 This signal is emitted when user has hovered away from a \a slice.
419
420 \sa QPieSlice::hoverLeave()
421 */
422
423 /*!
424 \fn void QPieSeries::added(QList<QPieSlice*> slices)
425
426 This signal is emitted when \a slices has been added to the series.
427
411
428 \sa append(), insert()
412 \sa QPieSlice::hovered()
429 */
430
431 /*!
432 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
433
434 This signal is emitted when \a slices has been removed from the series.
435
436 \sa remove(), clear()
437 */
438
439 /*!
440 \fn void QPieSeries::piePositionChanged()
441
442 This signal is emitted when pie position has changed.
443
444 \sa verticalPosition(), setVerticalPosition(), horizontalPosition(), setHorizontalPosition()
445 */
446
447 /*!
448 \fn void QPieSeries::pieSizeChanged()
449
450 This signal is emitted when pie size has changed.
451
452 \sa pieSize(), setPieSize()
453 */
413 */
454
414
455 /*!
415 /*!
@@ -582,34 +542,31 void QPieSeriesPrivate::updateDerivativeData()
582 PieSliceData::data(s).emitChangedSignal(s);
542 PieSliceData::data(s).emitChangedSignal(s);
583 }
543 }
584
544
585 void QPieSeriesPrivate::sliceChanged()
545 QPieSeriesPrivate* QPieSeriesPrivate::seriesData(QPieSeries &series)
586 {
546 {
587 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
547 return series.d_func();
588 updateDerivativeData();
589 }
548 }
590
549
591 void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons)
550 void QPieSeriesPrivate::sliceChanged()
592 {
551 {
593 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
552 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
594 Q_ASSERT(m_slices.contains(slice));
553 updateDerivativeData();
595 Q_Q(QPieSeries);
596 emit q->clicked(slice, buttons);
597 }
554 }
598
555
599 void QPieSeriesPrivate::sliceHoverEnter()
556 void QPieSeriesPrivate::sliceClicked()
600 {
557 {
601 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
558 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
602 Q_ASSERT(m_slices.contains(slice));
559 Q_ASSERT(m_slices.contains(slice));
603 Q_Q(QPieSeries);
560 Q_Q(QPieSeries);
604 emit q->hoverEnter(slice);
561 emit q->clicked(slice);
605 }
562 }
606
563
607 void QPieSeriesPrivate::sliceHoverLeave()
564 void QPieSeriesPrivate::sliceHovered(bool state)
608 {
565 {
609 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
566 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
610 Q_ASSERT(m_slices.contains(slice));
567 Q_ASSERT(m_slices.contains(slice));
611 Q_Q(QPieSeries);
568 Q_Q(QPieSeries);
612 emit q->hoverLeave(slice);
569 emit q->hovered(slice, state);
613 }
570 }
614
571
615 void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
572 void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
@@ -40,56 +40,44 public:
40 explicit QPieSeries(QObject *parent = 0);
40 explicit QPieSeries(QObject *parent = 0);
41 virtual ~QPieSeries();
41 virtual ~QPieSeries();
42
42
43 public: // from QChartSeries
44 QSeriesType type() const;
43 QSeriesType type() const;
45
44
46 public:
47
48 // slice setters
49 void append(QPieSlice* slice);
45 void append(QPieSlice* slice);
50 void append(QList<QPieSlice*> slices);
46 void append(QList<QPieSlice*> slices);
47 QPieSeries& operator << (QPieSlice* slice);
48 QPieSlice* append(qreal value, QString name);
51 void insert(int index, QPieSlice* slice);
49 void insert(int index, QPieSlice* slice);
52 void replace(QList<QPieSlice*> slices);
50 void replace(QList<QPieSlice*> slices);
53 void remove(QPieSlice* slice);
51 void remove(QPieSlice* slice);
54 void clear();
52 void clear();
55
53
56 // slice getters
57 QList<QPieSlice*> slices() const;
54 QList<QPieSlice*> slices() const;
58
59 // calculated data
60 int count() const;
55 int count() const;
61 bool isEmpty() const;
56 bool isEmpty() const;
57
62 qreal sum() const;
58 qreal sum() const;
63
59
64 // pie customization
65 void setHorizontalPosition(qreal relativePosition);
60 void setHorizontalPosition(qreal relativePosition);
66 qreal horizontalPosition() const;
61 qreal horizontalPosition() const;
67 void setVerticalPosition(qreal relativePosition);
62 void setVerticalPosition(qreal relativePosition);
68 qreal verticalPosition() const;
63 qreal verticalPosition() const;
64
69 void setPieSize(qreal relativeSize);
65 void setPieSize(qreal relativeSize);
70 qreal pieSize() const;
66 qreal pieSize() const;
67
71 void setPieStartAngle(qreal startAngle);
68 void setPieStartAngle(qreal startAngle);
72 qreal pieStartAngle() const;
69 qreal pieStartAngle() const;
73 void setPieEndAngle(qreal endAngle);
70 void setPieEndAngle(qreal endAngle);
74 qreal pieEndAngle() const;
71 qreal pieEndAngle() const;
75
72
76 // convenience function
77 QPieSeries& operator << (QPieSlice* slice);
78 QPieSlice* append(qreal value, QString name);
79 void setLabelsVisible(bool visible = true);
73 void setLabelsVisible(bool visible = true);
80
74
81 // data from model
82 bool setModel(QAbstractItemModel* model);
75 bool setModel(QAbstractItemModel* model);
83 void setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation = Qt::Vertical);
76 void setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation = Qt::Vertical);
84
77
85 Q_SIGNALS:
78 Q_SIGNALS:
86 void clicked(QPieSlice* slice, Qt::MouseButtons buttons);
79 void clicked(QPieSlice* slice);
87 void hoverEnter(QPieSlice* slice);
80 void hovered(QPieSlice* slice, bool state);
88 void hoverLeave(QPieSlice* slice);
89 void added(QList<QPieSlice*> slices);
90 void removed(QList<QPieSlice*> slices);
91 void piePositionChanged();
92 void pieSizeChanged();
93
81
94 private:
82 private:
95 Q_DECLARE_PRIVATE(QPieSeries)
83 Q_DECLARE_PRIVATE(QPieSeries)
@@ -27,6 +27,7
27 class QModelIndex;
27 class QModelIndex;
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 class QLegendPrivate;
30
31
31 class QPieSeriesPrivate : public QAbstractSeriesPrivate
32 class QPieSeriesPrivate : public QAbstractSeriesPrivate
32 {
33 {
@@ -37,16 +38,23 public:
37 ~QPieSeriesPrivate();
38 ~QPieSeriesPrivate();
38
39
39 void scaleDomain(Domain& domain);
40 void scaleDomain(Domain& domain);
40 Chart* createGraphics(ChartPresenter* presenter);
41 Chart* createGraphics(ChartPresenter *presenter);
41 QList<LegendMarker*> createLegendMarker(QLegend* legend);
42 QList<LegendMarker*> createLegendMarker(QLegend *legend);
42
43
43 void updateDerivativeData();
44 void updateDerivativeData();
44
45
46 static QPieSeriesPrivate* seriesData(QPieSeries &series);
47
48 Q_SIGNALS:
49 void added(QList<QPieSlice*> slices);
50 void removed(QList<QPieSlice*> slices);
51 void piePositionChanged();
52 void pieSizeChanged();
53
45 public Q_SLOTS:
54 public Q_SLOTS:
46 void sliceChanged();
55 void sliceChanged();
47 void sliceClicked(Qt::MouseButtons buttons);
56 void sliceClicked();
48 void sliceHoverEnter();
57 void sliceHovered(bool state);
49 void sliceHoverLeave();
50 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
58 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
51 void modelDataAdded(QModelIndex parent, int start, int end);
59 void modelDataAdded(QModelIndex parent, int start, int end);
52 void modelDataRemoved(QModelIndex parent, int start, int end);
60 void modelDataRemoved(QModelIndex parent, int start, int end);
@@ -65,7 +73,9 public:
65 int m_mapValues;
73 int m_mapValues;
66 int m_mapLabels;
74 int m_mapLabels;
67 Qt::Orientation m_mapOrientation;
75 Qt::Orientation m_mapOrientation;
76
68 private:
77 private:
78 friend class QLegendPrivate;
69 Q_DECLARE_PUBLIC(QPieSeries)
79 Q_DECLARE_PUBLIC(QPieSeries)
70 };
80 };
71
81
@@ -228,28 +228,21 qreal QPieSlice::labelArmLengthFactor() const
228 }
228 }
229
229
230 /*!
230 /*!
231 \fn void QPieSlice::clicked(Qt::MouseButtons buttons)
231 \fn void QPieSlice::clicked()
232
232
233 This signal is emitted when user has clicked the slice.
233 This signal is emitted when user has clicked the slice.
234 Parameter \a buttons hold the information about the clicked mouse buttons.
235
234
236 \sa QPieSeries::clicked()
235 \sa QPieSeries::clicked()
237 */
236 */
238
237
239 /*!
238 /*!
240 \fn void QPieSlice::hoverEnter()
239 \fn void QPieSlice::hovered(bool state)
241
240
242 This signal is emitted when user has hovered over the slice.
241 This signal is emitted when user has hovered over or away from the slice.
243
242
244 \sa QPieSeries::hoverEnter()
243 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
245 */
246
247 /*!
248 \fn void QPieSlice::hoverLeave()
249
250 This signal is emitted when user has hovered away from the slice.
251
244
252 \sa QPieSeries::hoverLeave()
245 \sa QPieSeries::hovered()
253 */
246 */
254
247
255 /*!
248 /*!
@@ -259,12 +252,6 qreal QPieSlice::labelArmLengthFactor() const
259 */
252 */
260
253
261 /*!
254 /*!
262 \fn void QPieSlice::selected()
263
264 This signal emitted when this slice has been clicked in the legend.
265 */
266
267 /*!
268 Sets the \a value of this slice.
255 Sets the \a value of this slice.
269 \sa value()
256 \sa value()
270 */
257 */
@@ -41,7 +41,6 public:
41 QPieSlice(qreal value, QString label, QObject *parent = 0);
41 QPieSlice(qreal value, QString label, QObject *parent = 0);
42 virtual ~QPieSlice();
42 virtual ~QPieSlice();
43
43
44 // data
45 void setValue(qreal value);
44 void setValue(qreal value);
46 qreal value() const;
45 qreal value() const;
47 void setLabel(QString label);
46 void setLabel(QString label);
@@ -51,12 +50,6 public:
51 void setExploded(bool exploded = true);
50 void setExploded(bool exploded = true);
52 bool isExploded() const;
51 bool isExploded() const;
53
52
54 // generated data
55 qreal percentage() const;
56 qreal startAngle() const;
57 qreal endAngle() const;
58
59 // customization
60 void setPen(const QPen &pen);
53 void setPen(const QPen &pen);
61 QPen pen() const;
54 QPen pen() const;
62 void setBrush(const QBrush &brush);
55 void setBrush(const QBrush &brush);
@@ -65,17 +58,20 public:
65 QPen labelPen() const;
58 QPen labelPen() const;
66 void setLabelFont(const QFont &font);
59 void setLabelFont(const QFont &font);
67 QFont labelFont() const;
60 QFont labelFont() const;
61
68 void setLabelArmLengthFactor(qreal factor);
62 void setLabelArmLengthFactor(qreal factor);
69 qreal labelArmLengthFactor() const;
63 qreal labelArmLengthFactor() const;
70 void setExplodeDistanceFactor(qreal factor);
64 void setExplodeDistanceFactor(qreal factor);
71 qreal explodeDistanceFactor() const;
65 qreal explodeDistanceFactor() const;
72
66
67 qreal percentage() const;
68 qreal startAngle() const;
69 qreal endAngle() const;
70
73 Q_SIGNALS:
71 Q_SIGNALS:
74 void clicked(Qt::MouseButtons buttons);
72 void clicked();
75 void hoverEnter();
73 void hovered(bool state);
76 void hoverLeave();
77 void changed();
74 void changed();
78 void selected();
79
75
80 private:
76 private:
81 friend class PieSliceData;
77 friend class PieSliceData;
General Comments 0
You need to be logged in to leave comments. Login now