@@ -111,7 +111,7 MainWidget::MainWidget(QWidget* parent) | |||||
111 | m_endAngle->setValue(m_series->pieEndAngle()); |
|
111 | m_endAngle->setValue(m_series->pieEndAngle()); | |
112 | m_endAngle->setSingleStep(1); |
|
112 | m_endAngle->setSingleStep(1); | |
113 |
|
113 | |||
114 |
QPushButton *a |
|
114 | QPushButton *appendSlice = new QPushButton("Append slice"); | |
115 | QPushButton *insertSlice = new QPushButton("Insert slice"); |
|
115 | QPushButton *insertSlice = new QPushButton("Insert slice"); | |
116 |
|
116 | |||
117 | QFormLayout* seriesSettingsLayout = new QFormLayout(); |
|
117 | QFormLayout* seriesSettingsLayout = new QFormLayout(); | |
@@ -120,7 +120,7 MainWidget::MainWidget(QWidget* parent) | |||||
120 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); |
|
120 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); | |
121 | seriesSettingsLayout->addRow("Start angle", m_startAngle); |
|
121 | seriesSettingsLayout->addRow("Start angle", m_startAngle); | |
122 | seriesSettingsLayout->addRow("End angle", m_endAngle); |
|
122 | seriesSettingsLayout->addRow("End angle", m_endAngle); | |
123 |
seriesSettingsLayout->addRow(a |
|
123 | seriesSettingsLayout->addRow(appendSlice); | |
124 | seriesSettingsLayout->addRow(insertSlice); |
|
124 | seriesSettingsLayout->addRow(insertSlice); | |
125 | QGroupBox* seriesSettings = new QGroupBox("Series"); |
|
125 | QGroupBox* seriesSettings = new QGroupBox("Series"); | |
126 | seriesSettings->setLayout(seriesSettingsLayout); |
|
126 | seriesSettings->setLayout(seriesSettingsLayout); | |
@@ -130,7 +130,7 MainWidget::MainWidget(QWidget* parent) | |||||
130 | connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
130 | connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
131 | connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
131 | connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
132 | connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
132 | connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
133 |
connect(a |
|
133 | connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice())); | |
134 | connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); |
|
134 | connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); | |
135 |
|
135 | |||
136 | // slice settings |
|
136 | // slice settings | |
@@ -295,7 +295,7 void MainWidget::showFontDialog() | |||||
295 | m_font->setText(dialog.currentFont().toString()); |
|
295 | m_font->setText(dialog.currentFont().toString()); | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 |
void MainWidget::a |
|
298 | void MainWidget::appendSlice() | |
299 | { |
|
299 | { | |
300 | *m_series << new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1)); |
|
300 | *m_series << new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1)); | |
301 | } |
|
301 | } | |
@@ -315,6 +315,8 void MainWidget::removeSlice() | |||||
315 | if (!m_slice) |
|
315 | if (!m_slice) | |
316 | return; |
|
316 | return; | |
317 |
|
317 | |||
|
318 | m_sliceName->setText("<click a slice>"); | |||
|
319 | ||||
318 | m_series->remove(m_slice); |
|
320 | m_series->remove(m_slice); | |
319 | m_slice = 0; |
|
321 | m_slice = 0; | |
320 | } |
|
322 | } |
@@ -53,7 +53,7 public Q_SLOTS: | |||||
53 | void updateSliceSettings(); |
|
53 | void updateSliceSettings(); | |
54 | void handleSliceClicked(QPieSlice* slice, Qt::MouseButtons buttons); |
|
54 | void handleSliceClicked(QPieSlice* slice, Qt::MouseButtons buttons); | |
55 | void showFontDialog(); |
|
55 | void showFontDialog(); | |
56 |
void a |
|
56 | void appendSlice(); | |
57 | void insertSlice(); |
|
57 | void insertSlice(); | |
58 | void removeSlice(); |
|
58 | void removeSlice(); | |
59 |
|
59 |
@@ -32,15 +32,15 int main(int argc, char *argv[]) | |||||
32 |
|
32 | |||
33 | //![1] |
|
33 | //![1] | |
34 | QPieSeries *series = new QPieSeries(); |
|
34 | QPieSeries *series = new QPieSeries(); | |
35 |
series->append(1, " |
|
35 | series->append(1, "Jane"); | |
36 |
series->append(2, " |
|
36 | series->append(2, "Joe"); | |
37 |
series->append(3, " |
|
37 | series->append(3, "Andy"); | |
38 |
series->append(4, " |
|
38 | series->append(4, "Barbara"); | |
39 |
series->append(5, " |
|
39 | series->append(5, "Axel"); | |
40 | //![1] |
|
40 | //![1] | |
41 |
|
41 | |||
42 | //![2] |
|
42 | //![2] | |
43 |
QPieSlice *slice = series->slices(). |
|
43 | QPieSlice *slice = series->slices().at(1); | |
44 | slice->setExploded(); |
|
44 | slice->setExploded(); | |
45 | slice->setLabelVisible(); |
|
45 | slice->setLabelVisible(); | |
46 | slice->setPen(QPen(Qt::darkGreen, 2)); |
|
46 | slice->setPen(QPen(Qt::darkGreen, 2)); |
@@ -27,9 +27,10 DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QSeries* drilldownSe | |||||
27 | m_prefix(prefix) |
|
27 | m_prefix(prefix) | |
28 | { |
|
28 | { | |
29 | setValue(value); |
|
29 | setValue(value); | |
30 | setLabelVisible(true); |
|
|||
31 | updateLabel(); |
|
30 | updateLabel(); | |
32 | connect(this, SIGNAL(changed()), this, SLOT(updateLabel())); |
|
31 | connect(this, SIGNAL(changed()), this, SLOT(updateLabel())); | |
|
32 | connect(this, SIGNAL(hoverEnter()), this, SLOT(showHighlight())); | |||
|
33 | connect(this, SIGNAL(hoverLeave()), this, SLOT(hideHighlight())); | |||
33 | } |
|
34 | } | |
34 |
|
35 | |||
35 | DrilldownSlice::~DrilldownSlice() |
|
36 | DrilldownSlice::~DrilldownSlice() | |
@@ -45,12 +46,24 QSeries* DrilldownSlice::drilldownSeries() const | |||||
45 | void DrilldownSlice::updateLabel() |
|
46 | void DrilldownSlice::updateLabel() | |
46 | { |
|
47 | { | |
47 | QString label = m_prefix; |
|
48 | QString label = m_prefix; | |
48 | label += " "; |
|
49 | label += " $"; | |
49 | label += QString::number(this->value()); |
|
50 | label += QString::number(this->value()); | |
50 |
label += " |
|
51 | label += ", "; | |
51 | label += QString::number(this->percentage()*100, 'f', 1); |
|
52 | label += QString::number(this->percentage()*100, 'f', 1); | |
52 | label += "%"; |
|
53 | label += "%"; | |
53 | setLabel(label); |
|
54 | setLabel(label); | |
54 | } |
|
55 | } | |
55 |
|
56 | |||
|
57 | void DrilldownSlice::showHighlight() | |||
|
58 | { | |||
|
59 | setExploded(); | |||
|
60 | setLabelVisible(); | |||
|
61 | } | |||
|
62 | ||||
|
63 | void DrilldownSlice::hideHighlight() | |||
|
64 | { | |||
|
65 | setExploded(false); | |||
|
66 | setLabelVisible(false); | |||
|
67 | } | |||
|
68 | ||||
56 | #include "moc_drilldownslice.cpp" |
|
69 | #include "moc_drilldownslice.cpp" |
@@ -39,6 +39,8 public: | |||||
39 |
|
39 | |||
40 | public Q_SLOTS: |
|
40 | public Q_SLOTS: | |
41 | void updateLabel(); |
|
41 | void updateLabel(); | |
|
42 | void showHighlight(); | |||
|
43 | void hideHighlight(); | |||
42 |
|
44 | |||
43 | private: |
|
45 | private: | |
44 | QSeries* m_drilldownSeries; |
|
46 | QSeries* m_drilldownSeries; |
@@ -24,6 +24,7 | |||||
24 | #include <QMainWindow> |
|
24 | #include <QMainWindow> | |
25 | #include <QTime> |
|
25 | #include <QTime> | |
26 | #include <QChartView> |
|
26 | #include <QChartView> | |
|
27 | #include <QLegend> | |||
27 | #include <QPieSeries> |
|
28 | #include <QPieSeries> | |
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
@@ -39,6 +40,8 int main(int argc, char *argv[]) | |||||
39 | DrilldownChart* chart = new DrilldownChart(); |
|
40 | DrilldownChart* chart = new DrilldownChart(); | |
40 | chart->setTheme(QChart::ChartThemeLight); |
|
41 | chart->setTheme(QChart::ChartThemeLight); | |
41 | chart->setAnimationOptions(QChart::AllAnimations); |
|
42 | chart->setAnimationOptions(QChart::AllAnimations); | |
|
43 | chart->legend()->setVisible(true); | |||
|
44 | chart->legend()->setAlignmnent(QLegend::AlignmentRight); | |||
42 |
|
45 | |||
43 | QPieSeries* yearSeries = new QPieSeries(&window); |
|
46 | QPieSeries* yearSeries = new QPieSeries(&window); | |
44 | yearSeries->setName("Sales by year - All"); |
|
47 | yearSeries->setName("Sales by year - All"); |
@@ -45,7 +45,10 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter) | |||||
45 |
|
45 | |||
46 | // Note: the following does not affect as long as the item does not have anything to paint |
|
46 | // Note: the following does not affect as long as the item does not have anything to paint | |
47 | setZValue(ChartPresenter::PieSeriesZValue); |
|
47 | setZValue(ChartPresenter::PieSeriesZValue); | |
48 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
48 | ||
|
49 | // If enabled slice boundingrect() is called instead of shape(). | |||
|
50 | // And this causes severe issues with mouse click & hover decection. | |||
|
51 | //setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |||
49 | } |
|
52 | } | |
50 |
|
53 | |||
51 | PieChartItem::~PieChartItem() |
|
54 | PieChartItem::~PieChartItem() |
General Comments 0
You need to be logged in to leave comments.
Login now