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