##// END OF EJS Templates
Renamed the "factor" stuff from pie series API.
Jani Honkonen -
r498:597882065a5e
parent child
Show More
@@ -1,97 +1,97
1 #include "mainwindow.h"
1 #include "mainwindow.h"
2 #include <qchartview.h>
2 #include <qchartview.h>
3 #include <qpieseries.h>
3 #include <qpieseries.h>
4 #include <qpieslice.h>
4 #include <qpieslice.h>
5 #include <qlineseries.h>
5 #include <qlineseries.h>
6 #include <qscatterseries.h>
6 #include <qscatterseries.h>
7 #include <qchartaxis.h>
7 #include <qchartaxis.h>
8 #include <QDebug>
8 #include <QDebug>
9
9
10 QTCOMMERCIALCHART_USE_NAMESPACE
10 QTCOMMERCIALCHART_USE_NAMESPACE
11
11
12 MainWindow::MainWindow(QWidget *parent)
12 MainWindow::MainWindow(QWidget *parent)
13 : QMainWindow(parent)
13 : QMainWindow(parent)
14 {
14 {
15 // Here's the set of company's colors used throughout the example
15 // Here's the set of company's colors used throughout the example
16 m_companyColor1 = "#b90020";
16 m_companyColor1 = "#b90020";
17 m_companyColor2 = "#6d0013";
17 m_companyColor2 = "#6d0013";
18 m_companyColor3 = "#d5d5f5";
18 m_companyColor3 = "#d5d5f5";
19 m_companyColor4 = "#fcfcfc";
19 m_companyColor4 = "#fcfcfc";
20
20
21 resize(400, 300);
21 resize(400, 300);
22 setWindowFlags(Qt::FramelessWindowHint);
22 setWindowFlags(Qt::FramelessWindowHint);
23
23
24 // Create chart view
24 // Create chart view
25 m_chartView = new QChartView(this);
25 m_chartView = new QChartView(this);
26 setCentralWidget(m_chartView);
26 setCentralWidget(m_chartView);
27 m_chartView->setChartTitle("Custom colors example");
27 m_chartView->setChartTitle("Custom colors example");
28 m_chartView->setRenderHint(QPainter::Antialiasing);
28 m_chartView->setRenderHint(QPainter::Antialiasing);
29
29
30 // Create line series
30 // Create line series
31 m_line = new QLineSeries();
31 m_line = new QLineSeries();
32 m_line->add(0.0, 1.1);
32 m_line->add(0.0, 1.1);
33 m_line->add(1.0, 2.3);
33 m_line->add(1.0, 2.3);
34 m_line->add(2.0, 2.1);
34 m_line->add(2.0, 2.1);
35 m_line->add(3.0, 3.3);
35 m_line->add(3.0, 3.3);
36 m_chartView->addSeries(m_line);
36 m_chartView->addSeries(m_line);
37
37
38 // Create scatter series with the same data
38 // Create scatter series with the same data
39 m_scatter = new QScatterSeries();
39 m_scatter = new QScatterSeries();
40 m_scatter->add(m_line->data());
40 m_scatter->add(m_line->data());
41 m_chartView->addSeries(m_scatter);
41 m_chartView->addSeries(m_scatter);
42
42
43 // Create pie series with different data
43 // Create pie series with different data
44 m_pie = new QPieSeries();
44 m_pie = new QPieSeries();
45 m_pie->add(1.1, "1");
45 m_pie->add(1.1, "1");
46 m_pie->add(2.1, "2");
46 m_pie->add(2.1, "2");
47 m_pie->add(3.0, "3");
47 m_pie->add(3.0, "3");
48 m_pie->setPositionFactors(0.7, 0.7);
48 m_pie->setPiePosition(0.7, 0.7);
49 m_pie->setSizeFactor(0.5);
49 m_pie->setPieSize(0.5);
50 m_chartView->addSeries(m_pie);
50 m_chartView->addSeries(m_pie);
51
51
52 connect(&m_timer, SIGNAL(timeout()), this, SLOT(customize()));
52 connect(&m_timer, SIGNAL(timeout()), this, SLOT(customize()));
53 m_timer.setInterval(1500);
53 m_timer.setInterval(1500);
54 m_timer.setSingleShot(false);
54 m_timer.setSingleShot(false);
55 m_timer.start();
55 m_timer.start();
56 }
56 }
57
57
58 MainWindow::~MainWindow()
58 MainWindow::~MainWindow()
59 {
59 {
60 }
60 }
61
61
62 void MainWindow::customize()
62 void MainWindow::customize()
63 {
63 {
64 // Customize chart background
64 // Customize chart background
65 // Use a gradient from color 3 to color 4 for chart background
65 // Use a gradient from color 3 to color 4 for chart background
66 QLinearGradient chartGradient(0, 0, 0, 300);
66 QLinearGradient chartGradient(0, 0, 0, 300);
67 chartGradient.setColorAt(0.0, m_companyColor3);
67 chartGradient.setColorAt(0.0, m_companyColor3);
68 chartGradient.setColorAt(0.5, m_companyColor4);
68 chartGradient.setColorAt(0.5, m_companyColor4);
69 chartGradient.setColorAt(1.0, m_companyColor3);
69 chartGradient.setColorAt(1.0, m_companyColor3);
70 m_chartView->setChartBackgroundBrush(chartGradient);
70 m_chartView->setChartBackgroundBrush(chartGradient);
71 m_chartView->setBackgroundBrush(m_companyColor4);
71 m_chartView->setBackgroundBrush(m_companyColor4);
72 m_chartView->setChartTitleBrush(m_companyColor1);
72 m_chartView->setChartTitleBrush(m_companyColor1);
73
73
74 // Customize chart axis
74 // Customize chart axis
75 QPen color1Pen(m_companyColor1, 4.0);
75 QPen color1Pen(m_companyColor1, 4.0);
76 m_chartView->axisX()->setAxisPen(color1Pen);
76 m_chartView->axisX()->setAxisPen(color1Pen);
77 m_chartView->axisY()->setAxisPen(color1Pen);
77 m_chartView->axisY()->setAxisPen(color1Pen);
78
78
79 // Customize series
79 // Customize series
80 m_line->setPen(color1Pen);
80 m_line->setPen(color1Pen);
81 m_scatter->setPen(color1Pen);
81 m_scatter->setPen(color1Pen);
82 m_scatter->setBrush(m_companyColor3);
82 m_scatter->setBrush(m_companyColor3);
83 for (int i(0); i < m_pie->slices().count(); i++) {
83 for (int i(0); i < m_pie->slices().count(); i++) {
84 Qt::BrushStyle style = static_cast<Qt::BrushStyle>(i + 1);
84 Qt::BrushStyle style = static_cast<Qt::BrushStyle>(i + 1);
85 m_pie->slices().at(i)->setSliceBrush(QBrush(m_companyColor2, style));
85 m_pie->slices().at(i)->setSliceBrush(QBrush(m_companyColor2, style));
86 m_pie->slices().at(i)->setSlicePen(color1Pen);
86 m_pie->slices().at(i)->setSlicePen(color1Pen);
87 }
87 }
88
88
89
89
90 // Calculate new colors to be used on the next update for the series
90 // Calculate new colors to be used on the next update for the series
91 m_companyColor1.setRed((m_companyColor1.red() + 25) % 255);
91 m_companyColor1.setRed((m_companyColor1.red() + 25) % 255);
92 m_companyColor1.setGreen((m_companyColor1.green() + 25) % 255);
92 m_companyColor1.setGreen((m_companyColor1.green() + 25) % 255);
93 m_companyColor1.setBlue((m_companyColor1.blue() + 25) % 255);
93 m_companyColor1.setBlue((m_companyColor1.blue() + 25) % 255);
94 m_companyColor2.setRed((m_companyColor2.red() + 25) % 255);
94 m_companyColor2.setRed((m_companyColor2.red() + 25) % 255);
95 m_companyColor2.setGreen((m_companyColor2.green() + 25) % 255);
95 m_companyColor2.setGreen((m_companyColor2.green() + 25) % 255);
96 m_companyColor2.setBlue((m_companyColor2.blue() + 25) % 255);
96 m_companyColor2.setBlue((m_companyColor2.blue() + 25) % 255);
97 }
97 }
@@ -1,236 +1,234
1 #include <QtGui/QApplication>
1 #include <QtGui/QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartglobal.h>
3 #include <qchartglobal.h>
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <qpieseries.h>
5 #include <qpieseries.h>
6 #include <qpieslice.h>
6 #include <qpieslice.h>
7 #include <QGridLayout>
7 #include <QGridLayout>
8 #include <QFormLayout>
8 #include <QFormLayout>
9 #include <QComboBox>
9 #include <QComboBox>
10 #include <QSpinBox>
10 #include <QSpinBox>
11 #include <QCheckBox>
11 #include <QCheckBox>
12 #include <QGroupBox>
12 #include <QGroupBox>
13 #include <QLabel>
13 #include <QLabel>
14
14
15 QTCOMMERCIALCHART_USE_NAMESPACE
15 QTCOMMERCIALCHART_USE_NAMESPACE
16
16
17 class CustomSlice : public QPieSlice
17 class CustomSlice : public QPieSlice
18 {
18 {
19 Q_OBJECT
19 Q_OBJECT
20 public:
20 public:
21 CustomSlice(qreal value, QString label)
21 CustomSlice(qreal value, QString label)
22 :QPieSlice(value, label)
22 :QPieSlice(value, label)
23 {
23 {
24 connect(this, SIGNAL(hoverEnter()), this, SLOT(handleHoverEnter()));
24 connect(this, SIGNAL(hoverEnter()), this, SLOT(handleHoverEnter()));
25 connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave()));
25 connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave()));
26 }
26 }
27
27
28 public Q_SLOTS:
28 public Q_SLOTS:
29
29
30 void handleHoverEnter()
30 void handleHoverEnter()
31 {
31 {
32 QBrush brush = this->sliceBrush();
32 QBrush brush = this->sliceBrush();
33 m_originalBrush = brush;
33 m_originalBrush = brush;
34 brush.setColor(brush.color().lighter());
34 brush.setColor(brush.color().lighter());
35 setSliceBrush(brush);
35 setSliceBrush(brush);
36 }
36 }
37
37
38 void handleHoverLeave()
38 void handleHoverLeave()
39 {
39 {
40 setSliceBrush(m_originalBrush);
40 setSliceBrush(m_originalBrush);
41 }
41 }
42
42
43 private:
43 private:
44 QBrush m_originalBrush;
44 QBrush m_originalBrush;
45 };
45 };
46
46
47 class MainWidget : public QWidget
47 class MainWidget : public QWidget
48 {
48 {
49 Q_OBJECT
49 Q_OBJECT
50
50
51 public:
51 public:
52 explicit MainWidget(QWidget* parent = 0)
52 explicit MainWidget(QWidget* parent = 0)
53 :QWidget(parent),
53 :QWidget(parent),
54 m_slice(0)
54 m_slice(0)
55 {
55 {
56 m_chartView = new QChartView();
56 m_chartView = new QChartView();
57 m_chartView->setChartTitle("Piechart customization");
57 m_chartView->setChartTitle("Piechart customization");
58 m_chartView->setRenderHint(QPainter::Antialiasing);
58 m_chartView->setRenderHint(QPainter::Antialiasing);
59 m_chartView->setChartTheme(QChart::ChartThemeIcy);
59 m_chartView->setChartTheme(QChart::ChartThemeIcy);
60
60
61 m_series = new QPieSeries();
61 m_series = new QPieSeries();
62 *m_series << new CustomSlice(10.0, "Slice 1");
62 *m_series << new CustomSlice(10.0, "Slice 1");
63 *m_series << new CustomSlice(20.0, "Slice 2");
63 *m_series << new CustomSlice(20.0, "Slice 2");
64 *m_series << new CustomSlice(30.0, "Slice 3");
64 *m_series << new CustomSlice(30.0, "Slice 3");
65 *m_series << new CustomSlice(40.0, "Slice 4");
65 *m_series << new CustomSlice(40.0, "Slice 4");
66 *m_series << new CustomSlice(50.0, "Slice 5");
66 *m_series << new CustomSlice(50.0, "Slice 5");
67 m_chartView->addSeries(m_series);
67 m_chartView->addSeries(m_series);
68
68
69 m_hPosition = new QDoubleSpinBox();
69 m_hPosition = new QDoubleSpinBox();
70 m_hPosition->setMinimum(0.0);
70 m_hPosition->setMinimum(0.0);
71 m_hPosition->setMaximum(1.0);
71 m_hPosition->setMaximum(1.0);
72 m_hPosition->setSingleStep(0.1);
72 m_hPosition->setSingleStep(0.1);
73 m_hPosition->setValue(m_series->horizontalPositionFactor());
73 m_hPosition->setValue(m_series->pieHorizontalPosition());
74
74
75 m_vPosition = new QDoubleSpinBox();
75 m_vPosition = new QDoubleSpinBox();
76 m_vPosition->setMinimum(0.0);
76 m_vPosition->setMinimum(0.0);
77 m_vPosition->setMaximum(1.0);
77 m_vPosition->setMaximum(1.0);
78 m_vPosition->setSingleStep(0.1);
78 m_vPosition->setSingleStep(0.1);
79 m_vPosition->setValue(m_series->verticalPositionFactor());
79 m_vPosition->setValue(m_series->pieVerticalPosition());
80
80
81 m_sizeFactor = new QDoubleSpinBox();
81 m_sizeFactor = new QDoubleSpinBox();
82 m_sizeFactor->setMinimum(0.0);
82 m_sizeFactor->setMinimum(0.0);
83 m_sizeFactor->setMaximum(1.0);
83 m_sizeFactor->setMaximum(1.0);
84 m_sizeFactor->setSingleStep(0.1);
84 m_sizeFactor->setSingleStep(0.1);
85 m_sizeFactor->setValue(m_series->sizeFactor());
85 m_sizeFactor->setValue(m_series->pieSize());
86
86
87 m_startAngle = new QDoubleSpinBox();
87 m_startAngle = new QDoubleSpinBox();
88 m_startAngle->setMinimum(0.0);
88 m_startAngle->setMinimum(0.0);
89 m_startAngle->setMaximum(360);
89 m_startAngle->setMaximum(360);
90 m_startAngle->setValue(m_series->startAngle());
90 m_startAngle->setValue(m_series->pieStartAngle());
91 m_startAngle->setSingleStep(1);
91 m_startAngle->setSingleStep(1);
92
92
93 m_endAngle = new QDoubleSpinBox();
93 m_endAngle = new QDoubleSpinBox();
94 m_endAngle->setMinimum(0.0);
94 m_endAngle->setMinimum(0.0);
95 m_endAngle->setMaximum(360);
95 m_endAngle->setMaximum(360);
96 m_endAngle->setValue(m_series->endAngle());
96 m_endAngle->setValue(m_series->pieEndAngle());
97 m_endAngle->setSingleStep(1);
97 m_endAngle->setSingleStep(1);
98
98
99 QFormLayout* seriesSettingsLayout = new QFormLayout();
99 QFormLayout* seriesSettingsLayout = new QFormLayout();
100 seriesSettingsLayout->addRow("Horizontal position", m_hPosition);
100 seriesSettingsLayout->addRow("Horizontal position", m_hPosition);
101 seriesSettingsLayout->addRow("Vertical position", m_vPosition);
101 seriesSettingsLayout->addRow("Vertical position", m_vPosition);
102 seriesSettingsLayout->addRow("Size factor", m_sizeFactor);
102 seriesSettingsLayout->addRow("Size factor", m_sizeFactor);
103 seriesSettingsLayout->addRow("Start angle", m_startAngle);
103 seriesSettingsLayout->addRow("Start angle", m_startAngle);
104 seriesSettingsLayout->addRow("End angle", m_endAngle);
104 seriesSettingsLayout->addRow("End angle", m_endAngle);
105 QGroupBox* seriesSettings = new QGroupBox("Series");
105 QGroupBox* seriesSettings = new QGroupBox("Series");
106 seriesSettings->setLayout(seriesSettingsLayout);
106 seriesSettings->setLayout(seriesSettingsLayout);
107
107
108 m_sliceName = new QLabel("<click a slice>");
108 m_sliceName = new QLabel("<click a slice>");
109 m_sliceValue = new QDoubleSpinBox();
109 m_sliceValue = new QDoubleSpinBox();
110 m_sliceValue->setMaximum(1000);
110 m_sliceValue->setMaximum(1000);
111 m_sliceLabelVisible = new QCheckBox();
111 m_sliceLabelVisible = new QCheckBox();
112 m_sliceLabelArmFactor = new QDoubleSpinBox();
112 m_sliceLabelArmFactor = new QDoubleSpinBox();
113 m_sliceLabelArmFactor->setSingleStep(0.01);
113 m_sliceLabelArmFactor->setSingleStep(0.01);
114 m_sliceExploded = new QCheckBox();
114 m_sliceExploded = new QCheckBox();
115 m_sliceExplodedFactor = new QDoubleSpinBox();
115 m_sliceExplodedFactor = new QDoubleSpinBox();
116 m_sliceExplodedFactor->setSingleStep(0.01);
116 m_sliceExplodedFactor->setSingleStep(0.01);
117
117
118 QFormLayout* sliceSettingsLayout = new QFormLayout();
118 QFormLayout* sliceSettingsLayout = new QFormLayout();
119 sliceSettingsLayout->addRow("Selected", m_sliceName);
119 sliceSettingsLayout->addRow("Selected", m_sliceName);
120 sliceSettingsLayout->addRow("Value", m_sliceValue);
120 sliceSettingsLayout->addRow("Value", m_sliceValue);
121 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
121 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
122 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
122 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
123 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
123 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
124 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
124 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
125
125
126 QGroupBox* sliceSettings = new QGroupBox("Slice");
126 QGroupBox* sliceSettings = new QGroupBox("Slice");
127 sliceSettings->setLayout(sliceSettingsLayout);
127 sliceSettings->setLayout(sliceSettingsLayout);
128
128
129 QGridLayout* baseLayout = new QGridLayout();
129 QGridLayout* baseLayout = new QGridLayout();
130 baseLayout->addWidget(seriesSettings, 0, 0);
130 baseLayout->addWidget(seriesSettings, 0, 0);
131 baseLayout->addWidget(sliceSettings, 1, 0);
131 baseLayout->addWidget(sliceSettings, 1, 0);
132 baseLayout->addWidget(m_chartView, 0, 1, 2, 1);
132 baseLayout->addWidget(m_chartView, 0, 1, 2, 1);
133 setLayout(baseLayout);
133 setLayout(baseLayout);
134
134
135 connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
135 connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
136 connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
136 connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
137 connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
137 connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
138 connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
138 connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
139 connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
139 connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
140
140
141 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
141 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
142 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
142 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
143 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
143 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
144 connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
144 connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
145 connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
145 connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
146
146
147 connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*)));
147 connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*)));
148
148
149 updateSerieSettings();
149 updateSerieSettings();
150 }
150 }
151
151
152 public Q_SLOTS:
152 public Q_SLOTS:
153
153
154 void updateSerieSettings()
154 void updateSerieSettings()
155 {
155 {
156 m_series->setPositionFactors(m_vPosition->value(), m_hPosition->value());
156 m_series->setPiePosition(m_vPosition->value(), m_hPosition->value());
157
157 m_series->setPieSize(m_sizeFactor->value());
158 m_series->setSizeFactor(m_sizeFactor->value());
158 m_series->setPieStartAngle(m_startAngle->value());
159
159 m_series->setPieEndAngle(m_endAngle->value());
160 m_series->setStartAngle(m_startAngle->value());
161 m_series->setEndAngle(m_endAngle->value());
162 }
160 }
163
161
164 void updateSliceSettings()
162 void updateSliceSettings()
165 {
163 {
166 if (!m_slice)
164 if (!m_slice)
167 return;
165 return;
168
166
169 m_slice->setValue(m_sliceValue->value());
167 m_slice->setValue(m_sliceValue->value());
170 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
168 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
171 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
169 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
172 m_slice->setExploded(m_sliceExploded->isChecked());
170 m_slice->setExploded(m_sliceExploded->isChecked());
173 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
171 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
174 }
172 }
175
173
176 void handleSliceClicked(QPieSlice* slice)
174 void handleSliceClicked(QPieSlice* slice)
177 {
175 {
178 m_slice = slice;
176 m_slice = slice;
179 m_sliceName->setText(slice->label());
177 m_sliceName->setText(slice->label());
180
178
181 m_sliceValue->blockSignals(true);
179 m_sliceValue->blockSignals(true);
182 m_sliceValue->setValue(slice->value());
180 m_sliceValue->setValue(slice->value());
183 m_sliceValue->blockSignals(false);
181 m_sliceValue->blockSignals(false);
184
182
185 m_sliceLabelVisible->blockSignals(true);
183 m_sliceLabelVisible->blockSignals(true);
186 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
184 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
187 m_sliceLabelVisible->blockSignals(false);
185 m_sliceLabelVisible->blockSignals(false);
188
186
189 m_sliceLabelArmFactor->blockSignals(true);
187 m_sliceLabelArmFactor->blockSignals(true);
190 m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor());
188 m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor());
191 m_sliceLabelArmFactor->blockSignals(false);
189 m_sliceLabelArmFactor->blockSignals(false);
192
190
193 m_sliceExploded->blockSignals(true);
191 m_sliceExploded->blockSignals(true);
194 m_sliceExploded->setChecked(slice->isExploded());
192 m_sliceExploded->setChecked(slice->isExploded());
195 m_sliceExploded->blockSignals(false);
193 m_sliceExploded->blockSignals(false);
196
194
197 m_sliceExplodedFactor->blockSignals(true);
195 m_sliceExplodedFactor->blockSignals(true);
198 m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor());
196 m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor());
199 m_sliceExplodedFactor->blockSignals(false);
197 m_sliceExplodedFactor->blockSignals(false);
200 }
198 }
201
199
202 private:
200 private:
203 QChartView* m_chartView;
201 QChartView* m_chartView;
204 QPieSeries* m_series;
202 QPieSeries* m_series;
205 QPieSlice* m_slice;
203 QPieSlice* m_slice;
206
204
207 QDoubleSpinBox* m_hPosition;
205 QDoubleSpinBox* m_hPosition;
208 QDoubleSpinBox* m_vPosition;
206 QDoubleSpinBox* m_vPosition;
209 QDoubleSpinBox* m_sizeFactor;
207 QDoubleSpinBox* m_sizeFactor;
210 QDoubleSpinBox* m_startAngle;
208 QDoubleSpinBox* m_startAngle;
211 QDoubleSpinBox* m_endAngle;
209 QDoubleSpinBox* m_endAngle;
212
210
213 QLabel* m_sliceName;
211 QLabel* m_sliceName;
214 QDoubleSpinBox* m_sliceValue;
212 QDoubleSpinBox* m_sliceValue;
215 QCheckBox* m_sliceLabelVisible;
213 QCheckBox* m_sliceLabelVisible;
216 QDoubleSpinBox* m_sliceLabelArmFactor;
214 QDoubleSpinBox* m_sliceLabelArmFactor;
217 QCheckBox* m_sliceExploded;
215 QCheckBox* m_sliceExploded;
218 QDoubleSpinBox* m_sliceExplodedFactor;
216 QDoubleSpinBox* m_sliceExplodedFactor;
219 };
217 };
220
218
221 int main(int argc, char *argv[])
219 int main(int argc, char *argv[])
222 {
220 {
223 QApplication a(argc, argv);
221 QApplication a(argc, argv);
224
222
225 QMainWindow window;
223 QMainWindow window;
226
224
227 MainWidget* widget = new MainWidget();
225 MainWidget* widget = new MainWidget();
228
226
229 window.setCentralWidget(widget);
227 window.setCentralWidget(widget);
230 window.resize(900, 600);
228 window.resize(900, 600);
231 window.show();
229 window.show();
232
230
233 return a.exec();
231 return a.exec();
234 }
232 }
235
233
236 #include "main.moc"
234 #include "main.moc"
@@ -1,158 +1,158
1 #include "piepresenter_p.h"
1 #include "piepresenter_p.h"
2 #include "pieslice_p.h"
2 #include "pieslice_p.h"
3 #include "qpieslice.h"
3 #include "qpieslice.h"
4 #include "qpieseries.h"
4 #include "qpieseries.h"
5 #include "chartpresenter_p.h"
5 #include "chartpresenter_p.h"
6 #include <QDebug>
6 #include <QDebug>
7 #include <QPainter>
7 #include <QPainter>
8
8
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 PiePresenter::PiePresenter(QGraphicsItem *parent, QPieSeries *series)
12 PiePresenter::PiePresenter(QGraphicsItem *parent, QPieSeries *series)
13 :ChartItem(parent),
13 :ChartItem(parent),
14 m_series(series)
14 m_series(series)
15 {
15 {
16 Q_ASSERT(series);
16 Q_ASSERT(series);
17 connect(series, SIGNAL(changed(const QPieSeries::ChangeSet&)), this, SLOT(handleSeriesChanged(const QPieSeries::ChangeSet&)));
17 connect(series, SIGNAL(changed(const QPieSeries::ChangeSet&)), this, SLOT(handleSeriesChanged(const QPieSeries::ChangeSet&)));
18 connect(series, SIGNAL(sizeFactorChanged()), this, SLOT(updateGeometry()));
18 connect(series, SIGNAL(piePositionChanged()), this, SLOT(updateGeometry()));
19 connect(series, SIGNAL(positionChanged()), this, SLOT(updateGeometry()));
19 connect(series, SIGNAL(pieSizeChanged()), this, SLOT(updateGeometry()));
20
20
21 if (m_series->count()) {
21 if (m_series->count()) {
22 QPieSeries::ChangeSet changeSet;
22 QPieSeries::ChangeSet changeSet;
23 changeSet.appendAdded(m_series->m_slices);
23 changeSet.appendAdded(m_series->m_slices);
24 handleSeriesChanged(changeSet);
24 handleSeriesChanged(changeSet);
25 }
25 }
26
26
27 // Note: the following does not affect as long as the item does not have anything to paint
27 // Note: the following does not affect as long as the item does not have anything to paint
28 setZValue(ChartPresenter::PieSeriesZValue);
28 setZValue(ChartPresenter::PieSeriesZValue);
29 }
29 }
30
30
31 PiePresenter::~PiePresenter()
31 PiePresenter::~PiePresenter()
32 {
32 {
33 // slices deleted automatically through QGraphicsItem
33 // slices deleted automatically through QGraphicsItem
34 }
34 }
35
35
36 void PiePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
36 void PiePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
37 {
37 {
38 // TODO: paint shadows for all components
38 // TODO: paint shadows for all components
39 // - get paths from items & merge & offset and draw with shadow color?
39 // - get paths from items & merge & offset and draw with shadow color?
40 //painter->setBrush(QBrush(Qt::red));
40 //painter->setBrush(QBrush(Qt::red));
41 //painter->drawRect(m_debugRect);
41 //painter->drawRect(m_debugRect);
42 }
42 }
43
43
44 void PiePresenter::handleSeriesChanged(const QPieSeries::ChangeSet& changeSet)
44 void PiePresenter::handleSeriesChanged(const QPieSeries::ChangeSet& changeSet)
45 {
45 {
46 //qDebug() << "PiePresenter::handleSeriesChanged()";
46 //qDebug() << "PiePresenter::handleSeriesChanged()";
47 //qDebug() << " added : " << changeSet.added();
47 //qDebug() << " added : " << changeSet.added();
48 //qDebug() << " changed: " << changeSet.changed();
48 //qDebug() << " changed: " << changeSet.changed();
49 //qDebug() << " removed: " << changeSet.removed();
49 //qDebug() << " removed: " << changeSet.removed();
50
50
51 foreach (QPieSlice* s, changeSet.added())
51 foreach (QPieSlice* s, changeSet.added())
52 addSlice(s);
52 addSlice(s);
53
53
54 foreach (QPieSlice* s, changeSet.changed())
54 foreach (QPieSlice* s, changeSet.changed())
55 updateSlice(s);
55 updateSlice(s);
56
56
57 foreach (QPieSlice* s, changeSet.removed())
57 foreach (QPieSlice* s, changeSet.removed())
58 deleteSlice(s);
58 deleteSlice(s);
59
59
60 // every change possibly changes the actual pie size
60 // every change possibly changes the actual pie size
61 updateGeometry();
61 updateGeometry();
62 }
62 }
63
63
64 void PiePresenter::handleDomainChanged(const Domain& domain)
64 void PiePresenter::handleDomainChanged(const Domain& domain)
65 {
65 {
66 // TODO
66 // TODO
67 }
67 }
68
68
69 void PiePresenter::handleGeometryChanged(const QRectF& rect)
69 void PiePresenter::handleGeometryChanged(const QRectF& rect)
70 {
70 {
71 m_rect = rect;
71 m_rect = rect;
72 prepareGeometryChange();
72 prepareGeometryChange();
73 updateGeometry();
73 updateGeometry();
74 }
74 }
75
75
76 void PiePresenter::updateGeometry()
76 void PiePresenter::updateGeometry()
77 {
77 {
78 if (!m_rect.isValid() || m_rect.isEmpty())
78 if (!m_rect.isValid() || m_rect.isEmpty())
79 return;
79 return;
80
80
81 // find pie center coordinates
81 // find pie center coordinates
82 QPointF center;
82 QPointF center;
83 center.setX(m_rect.left() + (m_rect.width() * m_series->m_hPositionFactor));
83 center.setX(m_rect.left() + (m_rect.width() * m_series->pieHorizontalPosition()));
84 center.setY(m_rect.top() + (m_rect.height() * m_series->m_vPositionFactor));
84 center.setY(m_rect.top() + (m_rect.height() * m_series->pieVerticalPosition()));
85
85
86 // find maximum radius for pie
86 // find maximum radius for pie
87 qreal radius = m_rect.height() / 2;
87 qreal radius = m_rect.height() / 2;
88 if (m_rect.width() < m_rect.height())
88 if (m_rect.width() < m_rect.height())
89 radius = m_rect.width() / 2;
89 radius = m_rect.width() / 2;
90
90
91 // apply size factor
91 // apply size factor
92 radius *= m_series->m_pieSizeFactor;
92 radius *= m_series->pieSize();
93
93
94 // update slices
94 // update slices
95 if (m_pieCenter != center || m_pieRadius != radius) {
95 if (m_pieCenter != center || m_pieRadius != radius) {
96 m_pieCenter = center;
96 m_pieCenter = center;
97 m_pieRadius = radius;
97 m_pieRadius = radius;
98 //qDebug() << "PiePresenter::updateGeometry()" << m_rect << m_pieCenter << m_pieRadius;
98 //qDebug() << "PiePresenter::updateGeometry()" << m_rect << m_pieCenter << m_pieRadius;
99 foreach (PieSlice* s, m_slices.values()) {
99 foreach (PieSlice* s, m_slices.values()) {
100 s->setPieCenterAndRadius(center, radius);
100 s->setPieCenterAndRadius(center, radius);
101 s->updateGeometry();
101 s->updateGeometry();
102 s->update();
102 s->update();
103 }
103 }
104 }
104 }
105
105
106 update();
106 update();
107 }
107 }
108
108
109 void PiePresenter::addSlice(QPieSlice* sliceData)
109 void PiePresenter::addSlice(QPieSlice* sliceData)
110 {
110 {
111 //qDebug() << "PiePresenter::addSlice()" << sliceData;
111 //qDebug() << "PiePresenter::addSlice()" << sliceData;
112
112
113 if (m_slices.keys().contains(sliceData)) {
113 if (m_slices.keys().contains(sliceData)) {
114 Q_ASSERT(0); // TODO: how to handle this nicely?
114 Q_ASSERT(0); // TODO: how to handle this nicely?
115 return;
115 return;
116 }
116 }
117
117
118 // create slice
118 // create slice
119 PieSlice *slice = new PieSlice(this);
119 PieSlice *slice = new PieSlice(this);
120 slice->setPieCenterAndRadius(m_pieCenter, m_pieRadius);
120 slice->setPieCenterAndRadius(m_pieCenter, m_pieRadius);
121 slice->updateData(sliceData);
121 slice->updateData(sliceData);
122 slice->updateGeometry();
122 slice->updateGeometry();
123 slice->update();
123 slice->update();
124 m_slices.insert(sliceData, slice);
124 m_slices.insert(sliceData, slice);
125
125
126 // connect signals
126 // connect signals
127 connect(slice, SIGNAL(clicked()), sliceData, SIGNAL(clicked()));
127 connect(slice, SIGNAL(clicked()), sliceData, SIGNAL(clicked()));
128 connect(slice, SIGNAL(hoverEnter()), sliceData, SIGNAL(hoverEnter()));
128 connect(slice, SIGNAL(hoverEnter()), sliceData, SIGNAL(hoverEnter()));
129 connect(slice, SIGNAL(hoverLeave()), sliceData, SIGNAL(hoverLeave()));
129 connect(slice, SIGNAL(hoverLeave()), sliceData, SIGNAL(hoverLeave()));
130 }
130 }
131
131
132 void PiePresenter::updateSlice(QPieSlice* sliceData)
132 void PiePresenter::updateSlice(QPieSlice* sliceData)
133 {
133 {
134 //qDebug() << "PiePresenter::updateSlice()" << sliceData;
134 //qDebug() << "PiePresenter::updateSlice()" << sliceData;
135
135
136 if (!m_slices.contains(sliceData)) {
136 if (!m_slices.contains(sliceData)) {
137 Q_ASSERT(0); // TODO: how to handle this nicely?
137 Q_ASSERT(0); // TODO: how to handle this nicely?
138 return;
138 return;
139 }
139 }
140
140
141 m_slices[sliceData]->updateData(sliceData);
141 m_slices[sliceData]->updateData(sliceData);
142 }
142 }
143
143
144 void PiePresenter::deleteSlice(QPieSlice* sliceData)
144 void PiePresenter::deleteSlice(QPieSlice* sliceData)
145 {
145 {
146 //qDebug() << "PiePresenter::deleteSlice()" << sliceData;
146 //qDebug() << "PiePresenter::deleteSlice()" << sliceData;
147
147
148 if (!m_slices.contains(sliceData)) {
148 if (!m_slices.contains(sliceData)) {
149 Q_ASSERT(0); // TODO: how to handle this nicely?
149 Q_ASSERT(0); // TODO: how to handle this nicely?
150 return;
150 return;
151 }
151 }
152
152
153 delete m_slices.take(sliceData);
153 delete m_slices.take(sliceData);
154 }
154 }
155
155
156 #include "moc_piepresenter_p.cpp"
156 #include "moc_piepresenter_p.cpp"
157
157
158 QTCOMMERCIALCHART_END_NAMESPACE
158 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,562 +1,563
1 #include "qpieseries.h"
1 #include "qpieseries.h"
2 #include "qpieslice.h"
2 #include "qpieslice.h"
3 #include <QDebug>
3 #include <QDebug>
4
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7
7
8 /*!
8 /*!
9 \class QPieSeries::ChangeSet
9 \class QPieSeries::ChangeSet
10 \brief Defines the changes in the series.
10 \brief Defines the changes in the series.
11
11
12 Contains the changes that have occurred in the series. Lists of added, changed and removed slices.
12 Contains the changes that have occurred in the series. Lists of added, changed and removed slices.
13
13
14 \sa QPieSeries::changed()
14 \sa QPieSeries::changed()
15 */
15 */
16
16
17 /*!
17 /*!
18 \internal
18 \internal
19 */
19 */
20 void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice)
20 void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice)
21 {
21 {
22 if (!m_added.contains(slice))
22 if (!m_added.contains(slice))
23 m_added << slice;
23 m_added << slice;
24 }
24 }
25
25
26 /*!
26 /*!
27 \internal
27 \internal
28 */
28 */
29 void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices)
29 void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices)
30 {
30 {
31 foreach (QPieSlice* s, slices)
31 foreach (QPieSlice* s, slices)
32 appendAdded(s);
32 appendAdded(s);
33 }
33 }
34
34
35 /*!
35 /*!
36 \internal
36 \internal
37 */
37 */
38 void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice)
38 void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice)
39 {
39 {
40 if (!m_changed.contains(slice))
40 if (!m_changed.contains(slice))
41 m_changed << slice;
41 m_changed << slice;
42 }
42 }
43
43
44 /*!
44 /*!
45 \internal
45 \internal
46 */
46 */
47 void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice)
47 void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice)
48 {
48 {
49 if (!m_removed.contains(slice))
49 if (!m_removed.contains(slice))
50 m_removed << slice;
50 m_removed << slice;
51 }
51 }
52
52
53 /*!
53 /*!
54 Returns a list of slices that have been added to the series.
54 Returns a list of slices that have been added to the series.
55 \sa QPieSeries::changed()
55 \sa QPieSeries::changed()
56 */
56 */
57 QList<QPieSlice*> QPieSeries::ChangeSet::added() const
57 QList<QPieSlice*> QPieSeries::ChangeSet::added() const
58 {
58 {
59 return m_added;
59 return m_added;
60 }
60 }
61
61
62 /*!
62 /*!
63 Returns a list of slices that have been changed in the series.
63 Returns a list of slices that have been changed in the series.
64 \sa QPieSeries::changed()
64 \sa QPieSeries::changed()
65 */
65 */
66 QList<QPieSlice*> QPieSeries::ChangeSet::changed() const
66 QList<QPieSlice*> QPieSeries::ChangeSet::changed() const
67 {
67 {
68 return m_changed;
68 return m_changed;
69 }
69 }
70
70
71 /*!
71 /*!
72 Returns a list of slices that have been removed from the series.
72 Returns a list of slices that have been removed from the series.
73 \sa QPieSeries::changed()
73 \sa QPieSeries::changed()
74 */
74 */
75 QList<QPieSlice*> QPieSeries::ChangeSet::removed() const
75 QList<QPieSlice*> QPieSeries::ChangeSet::removed() const
76 {
76 {
77 return m_removed;
77 return m_removed;
78 }
78 }
79
79
80
80
81 /*!
81 /*!
82 Returns true if there are no added/changed or removed slices in the change set.
82 Returns true if there are no added/changed or removed slices in the change set.
83 */
83 */
84 bool QPieSeries::ChangeSet::isEmpty() const
84 bool QPieSeries::ChangeSet::isEmpty() const
85 {
85 {
86 if (m_added.count() || m_changed.count() || m_removed.count())
86 if (m_added.count() || m_changed.count() || m_removed.count())
87 return false;
87 return false;
88 return true;
88 return true;
89 }
89 }
90
90
91 /*!
91 /*!
92 \class QPieSeries
92 \class QPieSeries
93 \brief Pie series API for QtCommercial Charts
93 \brief Pie series API for QtCommercial Charts
94
94
95 The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
95 The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
96 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
96 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
97 The actual slice size is determined by that relative value.
97 The actual slice size is determined by that relative value.
98
98
99 By default the pie is defined as a full pie but it can be a partial pie.
99 By default the pie is defined as a full pie but it can be a partial pie.
100 This can be done by setting a starting angle and angle span to the series.
100 This can be done by setting a starting angle and angle span to the series.
101 */
101 */
102
102
103 /*!
103 /*!
104 Constructs a series object which is a child of \a parent.
104 Constructs a series object which is a child of \a parent.
105 */
105 */
106 QPieSeries::QPieSeries(QObject *parent) :
106 QPieSeries::QPieSeries(QObject *parent) :
107 QSeries(parent),
107 QSeries(parent),
108 m_hPositionFactor(0.5),
108 m_pieRelativeHorPos(0.5),
109 m_vPositionFactor(0.5),
109 m_pieRelativeVerPos(0.5),
110 m_pieSizeFactor(0.7),
110 m_pieRelativeSize(0.7),
111 m_pieStartAngle(0),
111 m_pieStartAngle(0),
112 m_pieEndAngle(360),
112 m_pieEndAngle(360),
113 m_total(0)
113 m_total(0)
114 {
114 {
115
115
116 }
116 }
117
117
118 /*!
118 /*!
119 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
119 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
120 */
120 */
121 QPieSeries::~QPieSeries()
121 QPieSeries::~QPieSeries()
122 {
122 {
123
123
124 }
124 }
125
125
126 /*!
126 /*!
127 Returns QChartSeries::SeriesTypePie.
127 Returns QChartSeries::SeriesTypePie.
128 */
128 */
129 QSeries::QSeriesType QPieSeries::type() const
129 QSeries::QSeriesType QPieSeries::type() const
130 {
130 {
131 return QSeries::SeriesTypePie;
131 return QSeries::SeriesTypePie;
132 }
132 }
133
133
134 /*!
134 /*!
135 Sets an array of \a slices to the series replacing the existing slices.
135 Sets an array of \a slices to the series replacing the existing slices.
136 Slice ownership is passed to the series.
136 Slice ownership is passed to the series.
137 */
137 */
138 void QPieSeries::replace(QList<QPieSlice*> slices)
138 void QPieSeries::replace(QList<QPieSlice*> slices)
139 {
139 {
140 clear();
140 clear();
141 add(slices);
141 add(slices);
142 }
142 }
143
143
144 /*!
144 /*!
145 Adds an array of \a slices to the series.
145 Adds an array of \a slices to the series.
146 Slice ownership is passed to the series.
146 Slice ownership is passed to the series.
147 */
147 */
148 void QPieSeries::add(QList<QPieSlice*> slices)
148 void QPieSeries::add(QList<QPieSlice*> slices)
149 {
149 {
150 ChangeSet changeSet;
150 ChangeSet changeSet;
151 foreach (QPieSlice* s, slices) {
151 foreach (QPieSlice* s, slices) {
152 s->setParent(this);
152 s->setParent(this);
153 m_slices << s;
153 m_slices << s;
154 changeSet.appendAdded(s);
154 changeSet.appendAdded(s);
155 }
155 }
156
156
157 updateDerivativeData();
157 updateDerivativeData();
158
158
159 foreach (QPieSlice* s, slices) {
159 foreach (QPieSlice* s, slices) {
160 connect(s, SIGNAL(changed()), this, SLOT(sliceChanged()));
160 connect(s, SIGNAL(changed()), this, SLOT(sliceChanged()));
161 connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked()));
161 connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked()));
162 connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
162 connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
163 connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
163 connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
164 }
164 }
165
165
166 emit changed(changeSet);
166 emit changed(changeSet);
167 }
167 }
168
168
169 /*!
169 /*!
170 Adds a single \a slice to the series.
170 Adds a single \a slice to the series.
171 Slice ownership is passed to the series.
171 Slice ownership is passed to the series.
172 */
172 */
173 void QPieSeries::add(QPieSlice* slice)
173 void QPieSeries::add(QPieSlice* slice)
174 {
174 {
175 add(QList<QPieSlice*>() << slice);
175 add(QList<QPieSlice*>() << slice);
176 }
176 }
177
177
178 /*!
178 /*!
179 Adds a single \a slice to the series and returns a reference to the series.
179 Adds a single \a slice to the series and returns a reference to the series.
180 Slice ownership is passed to the series.
180 Slice ownership is passed to the series.
181 */
181 */
182 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
182 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
183 {
183 {
184 add(slice);
184 add(slice);
185 return *this;
185 return *this;
186 }
186 }
187
187
188
188
189 /*!
189 /*!
190 Adds a single slice to the series with give \a value and \a name.
190 Adds a single slice to the series with give \a value and \a name.
191 Slice ownership is passed to the series.
191 Slice ownership is passed to the series.
192 */
192 */
193 QPieSlice* QPieSeries::add(qreal value, QString name)
193 QPieSlice* QPieSeries::add(qreal value, QString name)
194 {
194 {
195 QPieSlice* slice = new QPieSlice(value, name);
195 QPieSlice* slice = new QPieSlice(value, name);
196 add(slice);
196 add(slice);
197 return slice;
197 return slice;
198 }
198 }
199
199
200 /*!
200 /*!
201 Removes a single \a slice from the series and deletes the slice.
201 Removes a single \a slice from the series and deletes the slice.
202
202
203 Do not reference this pointer after this call.
203 Do not reference this pointer after this call.
204 */
204 */
205 void QPieSeries::remove(QPieSlice* slice)
205 void QPieSeries::remove(QPieSlice* slice)
206 {
206 {
207 if (!m_slices.removeOne(slice)) {
207 if (!m_slices.removeOne(slice)) {
208 Q_ASSERT(0); // TODO: how should this be reported?
208 Q_ASSERT(0); // TODO: how should this be reported?
209 return;
209 return;
210 }
210 }
211
211
212 ChangeSet changeSet;
212 ChangeSet changeSet;
213 changeSet.appendRemoved(slice);
213 changeSet.appendRemoved(slice);
214 emit changed(changeSet);
214 emit changed(changeSet);
215
215
216 delete slice;
216 delete slice;
217 slice = NULL;
217 slice = NULL;
218
218
219 updateDerivativeData();
219 updateDerivativeData();
220 }
220 }
221
221
222 /*!
222 /*!
223 Clears all slices from the series.
223 Clears all slices from the series.
224 */
224 */
225 void QPieSeries::clear()
225 void QPieSeries::clear()
226 {
226 {
227 if (m_slices.count() == 0)
227 if (m_slices.count() == 0)
228 return;
228 return;
229
229
230 ChangeSet changeSet;
230 ChangeSet changeSet;
231 foreach (QPieSlice* s, m_slices) {
231 foreach (QPieSlice* s, m_slices) {
232 changeSet.appendRemoved(s);
232 changeSet.appendRemoved(s);
233 m_slices.removeOne(s);
233 m_slices.removeOne(s);
234 delete s;
234 delete s;
235 }
235 }
236 emit changed(changeSet);
236 emit changed(changeSet);
237 updateDerivativeData();
237 updateDerivativeData();
238 }
238 }
239
239
240 /*!
240 /*!
241 Counts the number of the slices in this series.
241 Counts the number of the slices in this series.
242 */
242 */
243 int QPieSeries::count() const
243 int QPieSeries::count() const
244 {
244 {
245 return m_slices.count();
245 return m_slices.count();
246 }
246 }
247
247
248 /*!
248 /*!
249 Returns a list of slices that belong to this series.
249 Returns a list of slices that belong to this series.
250 */
250 */
251 QList<QPieSlice*> QPieSeries::slices() const
251 QList<QPieSlice*> QPieSeries::slices() const
252 {
252 {
253 return m_slices;
253 return m_slices;
254 }
254 }
255
255
256 /*!
256 /*!
257 Sets the center position of the pie by \a horizontalFactor and \a verticalFactor.
257 Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition.
258
258
259 The factors are relative to the chart rectangle where:
259 The factors are relative to the chart rectangle where:
260
260
261 \a horizontalFactor 0.0 means the absolute left.
261 \a relativeHorizontalPosition 0.0 means the absolute left.
262 \a horizontalFactor 1.0 means the absolute right.
262 \a relativeHorizontalPosition 1.0 means the absolute right.
263 \a verticalFactor 0.0 means the absolute top.
263 \a relativeVerticalPosition 0.0 means the absolute top.
264 \a verticalFactor 1.0 means the absolute bottom.
264 \a relativeVerticalPosition 1.0 means the absolute bottom.
265
265
266 By default \a horizontalFactor and \a verticalFactor are 0.5 which puts the pie in the middle of the chart rectangle.
266 By default both values are 0.5 which puts the pie in the middle of the chart rectangle.
267
267
268 \sa horizontalPositionFactor(), verticalPositionFactor(), setSizeFactor()
268 \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize()
269 */
269 */
270 void QPieSeries::setPositionFactors(qreal horizontalFactor, qreal verticalFactor)
270 void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition)
271 {
271 {
272 if (horizontalFactor < 0.0 || horizontalFactor > 1.0 || verticalFactor < 0.0 || verticalFactor > 1.0)
272 if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 ||
273 relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0)
273 return;
274 return;
274
275
275 if (m_hPositionFactor != horizontalFactor || m_vPositionFactor != verticalFactor) {
276 if (m_pieRelativeHorPos != relativeHorizontalPosition || m_pieRelativeVerPos != relativeVerticalPosition) {
276 m_hPositionFactor = horizontalFactor;
277 m_pieRelativeHorPos = relativeHorizontalPosition;
277 m_vPositionFactor = verticalFactor;
278 m_pieRelativeVerPos = relativeVerticalPosition;
278 emit positionChanged();
279 emit piePositionChanged();
279 }
280 }
280 }
281 }
281
282
282 /*!
283 /*!
283 Gets the horizontal position factor of the pie.
284 Gets the horizontal position of the pie.
284
285
285 The factors are relative to the chart rectangle where:
286 The returned value is relative to the chart rectangle where:
286
287
287 Horizontal factor 0.0 means the absolute left.
288 0.0 means the absolute left.
288 Horizontal factor 1.0 means the absolute right.
289 1.0 means the absolute right.
289
290
290 By default horizontal factor is 0.5 which puts the pie in the horizontal middle of the chart rectangle.
291 By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle.
291
292
292 \sa setPositionFactors(), verticalPositionFactor(), setSizeFactor()
293 \sa setPiePosition(), pieVerticalPosition(), setPieSize()
293 */
294 */
294 qreal QPieSeries::horizontalPositionFactor() const
295 qreal QPieSeries::pieHorizontalPosition() const
295 {
296 {
296 return m_hPositionFactor;
297 return m_pieRelativeHorPos;
297 }
298 }
298
299
299 /*!
300 /*!
300 Gets the vertical position factor of the pie.
301 Gets the vertical position position of the pie.
301
302
302 The factors are relative to the chart rectangle where:
303 The returned value is relative to the chart rectangle where:
303
304
304 Vertical factor 0.0 means the absolute top.
305 0.0 means the absolute top.
305 Vertical factor 1.0 means the absolute bottom.
306 1.0 means the absolute bottom.
306
307
307 By default vertical factor is 0.5 which puts the pie in the vertical middle of the chart rectangle.
308 By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle.
308
309
309 \sa setPositionFactors(), horizontalPositionFactor(), setSizeFactor()
310 \sa setPiePosition(), pieHorizontalPosition(), setPieSize()
310 */
311 */
311 qreal QPieSeries::verticalPositionFactor() const
312 qreal QPieSeries::pieVerticalPosition() const
312 {
313 {
313 return m_vPositionFactor;
314 return m_pieRelativeVerPos;
314 }
315 }
315
316
316 /*!
317 /*!
317 Sets the size \a sizeFactor of the pie.
318 Sets the relative size of the pie.
318
319
319 The size factor is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
320 The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
320
321
321 Default value is 0.7.
322 Default value is 0.7.
322
323
323 \sa sizeFactor(), setPositionFactors(), verticalPositionFactor(), horizontalPositionFactor()
324 \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
324 */
325 */
325 void QPieSeries::setSizeFactor(qreal sizeFactor)
326 void QPieSeries::setPieSize(qreal relativeSize)
326 {
327 {
327 if (sizeFactor < 0.0)
328 if (relativeSize < 0.0 || relativeSize > 1.0)
328 return;
329 return;
329
330
330 if (m_pieSizeFactor != sizeFactor) {
331 if (m_pieRelativeSize != relativeSize) {
331 m_pieSizeFactor = sizeFactor;
332 m_pieRelativeSize = relativeSize;
332 emit sizeFactorChanged();
333 emit pieSizeChanged();
333 }
334 }
334 }
335 }
335
336
336 /*!
337 /*!
337 Gets the size factor of the pie.
338 Gets the relative size of the pie.
338
339
339 The size factor is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
340 The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
340
341
341 Default value is 0.7.
342 Default value is 0.7.
342
343
343 \sa setSizeFactor(), setPositionFactors(), verticalPositionFactor(), horizontalPositionFactor()
344 \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
344 */
345 */
345 qreal QPieSeries::sizeFactor() const
346 qreal QPieSeries::pieSize() const
346 {
347 {
347 return m_pieSizeFactor;
348 return m_pieRelativeSize;
348 }
349 }
349
350
350
351
351 /*!
352 /*!
352 Sets the end angle of the pie.
353 Sets the end angle of the pie.
353
354
354 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
355 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
355
356
356 \a startAngle must be less than end angle. Default value is 0.
357 \a angle must be less than pie end angle. Default value is 0.
357
358
358 \sa startAngle(), endAngle(), setEndAngle()
359 \sa pieStartAngle(), pieEndAngle(), setPieEndAngle()
359 */
360 */
360 void QPieSeries::setStartAngle(qreal startAngle)
361 void QPieSeries::setPieStartAngle(qreal angle)
361 {
362 {
362 if (startAngle >= 0 && startAngle <= 360 && startAngle != m_pieStartAngle && startAngle <= m_pieEndAngle) {
363 if (angle >= 0 && angle <= 360 && angle != m_pieStartAngle && angle <= m_pieEndAngle) {
363 m_pieStartAngle = startAngle;
364 m_pieStartAngle = angle;
364 updateDerivativeData();
365 updateDerivativeData();
365 }
366 }
366 }
367 }
367
368
368 /*!
369 /*!
369 Gets the start angle of the pie.
370 Gets the start angle of the pie.
370
371
371 Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360.
372 Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360.
372
373
373 \sa setStartAngle(), endAngle(), setEndAngle()
374 \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle()
374 */
375 */
375 qreal QPieSeries::startAngle() const
376 qreal QPieSeries::pieStartAngle() const
376 {
377 {
377 return m_pieStartAngle;
378 return m_pieStartAngle;
378 }
379 }
379
380
380 /*!
381 /*!
381 Sets the end angle of the pie.
382 Sets the end angle of the pie.
382
383
383 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
384 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
384
385
385 \a endAngle must be greater than start angle.
386 \a angle must be greater than start angle.
386
387
387 \sa endAngle(), startAngle(), setStartAngle()
388 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
388 */
389 */
389 void QPieSeries::setEndAngle(qreal endAngle)
390 void QPieSeries::setPieEndAngle(qreal angle)
390 {
391 {
391 if (endAngle >= 0 && endAngle <= 360 && endAngle != m_pieEndAngle && endAngle >= m_pieStartAngle) {
392 if (angle >= 0 && angle <= 360 && angle != m_pieEndAngle && angle >= m_pieStartAngle) {
392 m_pieEndAngle = endAngle;
393 m_pieEndAngle = angle;
393 updateDerivativeData();
394 updateDerivativeData();
394 }
395 }
395 }
396 }
396
397
397 /*!
398 /*!
398 Returns the end angle of the pie.
399 Returns the end angle of the pie.
399
400
400 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
401 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
401
402
402 \sa setEndAngle(), startAngle(), setStartAngle()
403 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
403 */
404 */
404 qreal QPieSeries::endAngle() const
405 qreal QPieSeries::pieEndAngle() const
405 {
406 {
406 return m_pieEndAngle;
407 return m_pieEndAngle;
407 }
408 }
408
409
409 /*!
410 /*!
410 Sets the all the slice labels \a visible or invisible.
411 Sets the all the slice labels \a visible or invisible.
411
412
412 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
413 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
413 */
414 */
414 void QPieSeries::setLabelsVisible(bool visible)
415 void QPieSeries::setLabelsVisible(bool visible)
415 {
416 {
416 foreach (QPieSlice* s, m_slices)
417 foreach (QPieSlice* s, m_slices)
417 s->setLabelVisible(visible);
418 s->setLabelVisible(visible);
418 }
419 }
419
420
420 /*!
421 /*!
421 Returns the sum of all slice values in this series.
422 Returns the sum of all slice values in this series.
422
423
423 \sa QPieSlice::value(), QPieSlice::setValue()
424 \sa QPieSlice::value(), QPieSlice::setValue()
424 */
425 */
425 qreal QPieSeries::total() const
426 qreal QPieSeries::total() const
426 {
427 {
427 return m_total;
428 return m_total;
428 }
429 }
429
430
430 /*!
431 /*!
431 \fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet)
432 \fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet)
432
433
433 This signal emitted when something has changed in the series.
434 This signal emitted when something has changed in the series.
434 The \a changeSet contains the details of which slices have been added, changed or removed.
435 The \a changeSet contains the details of which slices have been added, changed or removed.
435
436
436 \sa QPieSeries::ChangeSet, QPieSlice::changed()
437 \sa QPieSeries::ChangeSet, QPieSlice::changed()
437 */
438 */
438
439
439 /*!
440 /*!
440 \fn void QPieSeries::clicked(QPieSlice* slice)
441 \fn void QPieSeries::clicked(QPieSlice* slice)
441
442
442 This signal is emitted when a \a slice has been clicked.
443 This signal is emitted when a \a slice has been clicked.
443
444
444 \sa QPieSlice::clicked()
445 \sa QPieSlice::clicked()
445 */
446 */
446
447
447 /*!
448 /*!
448 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
449 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
449
450
450 This signal is emitted when user has hovered over a \a slice.
451 This signal is emitted when user has hovered over a \a slice.
451
452
452 \sa QPieSlice::hoverEnter()
453 \sa QPieSlice::hoverEnter()
453 */
454 */
454
455
455 /*!
456 /*!
456 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
457 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
457
458
458 This signal is emitted when user has hovered away from a \a slice.
459 This signal is emitted when user has hovered away from a \a slice.
459
460
460 \sa QPieSlice::hoverLeave()
461 \sa QPieSlice::hoverLeave()
461 */
462 */
462
463
463 /*!
464 /*!
464 \fn void QPieSeries::sizeFactorChanged()
465 \fn void QPieSeries::pieSizeChanged()
465
466
466 This signal is emitted when size factor has been changed.
467 This signal is emitted when size factor has been changed.
467
468
468 \sa sizeFactor(), setSizeFactor()
469 \sa pieSize(), setPieSize()
469 */
470 */
470
471
471 /*!
472 /*!
472 \fn void QPieSeries::positionChanged()
473 \fn void QPieSeries::piePositionChanged()
473
474
474 This signal is emitted when position of the pie has been changed.
475 This signal is emitted when position of the pie has been changed.
475
476
476 \sa horizontalPositionFactor(), verticalPositionFactor(), setPositionFactors()
477 \sa pieHorizontalPosition(), pieVerticalPosition(), setPiePosition()
477 */
478 */
478
479
479 void QPieSeries::sliceChanged()
480 void QPieSeries::sliceChanged()
480 {
481 {
481 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
482 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
482 Q_ASSERT(m_slices.contains(slice));
483 Q_ASSERT(m_slices.contains(slice));
483
484
484 ChangeSet changeSet;
485 ChangeSet changeSet;
485 changeSet.appendChanged(slice);
486 changeSet.appendChanged(slice);
486 emit changed(changeSet);
487 emit changed(changeSet);
487
488
488 updateDerivativeData();
489 updateDerivativeData();
489 }
490 }
490
491
491 void QPieSeries::sliceClicked()
492 void QPieSeries::sliceClicked()
492 {
493 {
493 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
494 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
494 Q_ASSERT(m_slices.contains(slice));
495 Q_ASSERT(m_slices.contains(slice));
495 emit clicked(slice);
496 emit clicked(slice);
496 }
497 }
497
498
498 void QPieSeries::sliceHoverEnter()
499 void QPieSeries::sliceHoverEnter()
499 {
500 {
500 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
501 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
501 Q_ASSERT(m_slices.contains(slice));
502 Q_ASSERT(m_slices.contains(slice));
502 emit hoverEnter(slice);
503 emit hoverEnter(slice);
503 }
504 }
504
505
505 void QPieSeries::sliceHoverLeave()
506 void QPieSeries::sliceHoverLeave()
506 {
507 {
507 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
508 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
508 Q_ASSERT(m_slices.contains(slice));
509 Q_ASSERT(m_slices.contains(slice));
509 emit hoverLeave(slice);
510 emit hoverLeave(slice);
510 }
511 }
511
512
512 void QPieSeries::updateDerivativeData()
513 void QPieSeries::updateDerivativeData()
513 {
514 {
514 m_total = 0;
515 m_total = 0;
515
516
516 // nothing to do?
517 // nothing to do?
517 if (m_slices.count() == 0)
518 if (m_slices.count() == 0)
518 return;
519 return;
519
520
520 // calculate total
521 // calculate total
521 foreach (QPieSlice* s, m_slices)
522 foreach (QPieSlice* s, m_slices)
522 m_total += s->value();
523 m_total += s->value();
523
524
524 // we must have some values
525 // we must have some values
525 if (m_total == 0) {
526 if (m_total == 0) {
526 qDebug() << "QPieSeries::updateDerivativeData() total == 0";
527 qDebug() << "QPieSeries::updateDerivativeData() total == 0";
527 Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this?
528 Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this?
528 }
529 }
529
530
530 // update slice attributes
531 // update slice attributes
531 qreal sliceAngle = m_pieStartAngle;
532 qreal sliceAngle = m_pieStartAngle;
532 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
533 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
533 foreach (QPieSlice* s, m_slices) {
534 foreach (QPieSlice* s, m_slices) {
534
535
535 bool changed = false;
536 bool changed = false;
536
537
537 qreal percentage = s->value() / m_total;
538 qreal percentage = s->value() / m_total;
538 if (s->m_percentage != percentage) {
539 if (s->m_percentage != percentage) {
539 s->m_percentage = percentage;
540 s->m_percentage = percentage;
540 changed = true;
541 changed = true;
541 }
542 }
542
543
543 qreal sliceSpan = pieSpan * percentage;
544 qreal sliceSpan = pieSpan * percentage;
544 if (s->m_angleSpan != sliceSpan) {
545 if (s->m_angleSpan != sliceSpan) {
545 s->m_angleSpan = sliceSpan;
546 s->m_angleSpan = sliceSpan;
546 changed = true;
547 changed = true;
547 }
548 }
548
549
549 if (s->m_startAngle != sliceAngle) {
550 if (s->m_startAngle != sliceAngle) {
550 s->m_startAngle = sliceAngle;
551 s->m_startAngle = sliceAngle;
551 changed = true;
552 changed = true;
552 }
553 }
553 sliceAngle += sliceSpan;
554 sliceAngle += sliceSpan;
554
555
555 if (changed)
556 if (changed)
556 emit s->changed();
557 emit s->changed();
557 }
558 }
558 }
559 }
559
560
560 #include "moc_qpieseries.cpp"
561 #include "moc_qpieseries.cpp"
561
562
562 QTCOMMERCIALCHART_END_NAMESPACE
563 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,134 +1,133
1 #ifndef PIESERIES_H
1 #ifndef PIESERIES_H
2 #define PIESERIES_H
2 #define PIESERIES_H
3
3
4 #include "qseries.h"
4 #include "qseries.h"
5 #include <QObject>
5 #include <QObject>
6 #include <QRectF>
6 #include <QRectF>
7 #include <QColor>
7 #include <QColor>
8 #include <QPen>
8 #include <QPen>
9 #include <QBrush>
9 #include <QBrush>
10 #include <QSignalMapper>
10 #include <QSignalMapper>
11
11
12 class QGraphicsObject;
12 class QGraphicsObject;
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14 class PiePresenter;
14 class PiePresenter;
15 class PieSlice;
15 class PieSlice;
16 class QPieSlice;
16 class QPieSlice;
17
17
18 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries
18 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries
19 {
19 {
20 Q_OBJECT
20 Q_OBJECT
21
21
22 public:
22 public:
23
23
24 class ChangeSet
24 class ChangeSet
25 {
25 {
26 public:
26 public:
27
27
28 // TODO: these should not really be exposed to the public API
28 // TODO: these should not really be exposed to the public API
29 void appendAdded(QPieSlice* slice);
29 void appendAdded(QPieSlice* slice);
30 void appendAdded(QList<QPieSlice*> slices);
30 void appendAdded(QList<QPieSlice*> slices);
31 void appendChanged(QPieSlice* slice);
31 void appendChanged(QPieSlice* slice);
32 void appendRemoved(QPieSlice* slice);
32 void appendRemoved(QPieSlice* slice);
33
33
34 QList<QPieSlice*> added() const;
34 QList<QPieSlice*> added() const;
35 QList<QPieSlice*> changed() const;
35 QList<QPieSlice*> changed() const;
36 QList<QPieSlice*> removed() const;
36 QList<QPieSlice*> removed() const;
37
37
38 bool isEmpty() const;
38 bool isEmpty() const;
39
39
40 private:
40 private:
41 QList<QPieSlice*> m_added;
41 QList<QPieSlice*> m_added;
42 QList<QPieSlice*> m_changed;
42 QList<QPieSlice*> m_changed;
43 QList<QPieSlice*> m_removed;
43 QList<QPieSlice*> m_removed;
44 };
44 };
45
45
46 public:
46 public:
47 QPieSeries(QObject *parent = 0);
47 QPieSeries(QObject *parent = 0);
48 virtual ~QPieSeries();
48 virtual ~QPieSeries();
49
49
50 public: // from QChartSeries
50 public: // from QChartSeries
51 QSeriesType type() const;
51 QSeriesType type() const;
52
52
53 public:
53 public:
54
54
55 // slice setters
55 // slice setters
56 void add(QPieSlice* slice);
56 void add(QPieSlice* slice);
57 void add(QList<QPieSlice*> slices);
57 void add(QList<QPieSlice*> slices);
58 void replace(QList<QPieSlice*> slices);
58 void replace(QList<QPieSlice*> slices);
59 void remove(QPieSlice* slice);
59 void remove(QPieSlice* slice);
60 void clear();
60 void clear();
61
61
62 // sluce getters
62 // sluce getters
63 QList<QPieSlice*> slices() const;
63 QList<QPieSlice*> slices() const;
64
64
65 // calculated data
65 // calculated data
66 int count() const;
66 int count() const;
67 qreal total() const;
67 qreal total() const;
68
68
69 // pie customization
69 // pie customization
70 void setPositionFactors(qreal horizontalFactor, qreal verticalFactor);
70 void setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition);
71 qreal horizontalPositionFactor() const;
71 qreal pieHorizontalPosition() const;
72 qreal verticalPositionFactor() const;
72 qreal pieVerticalPosition() const;
73 void setSizeFactor(qreal sizeFactor);
73 void setPieSize(qreal relativeSize);
74 qreal sizeFactor() const;
74 qreal pieSize() const;
75 void setStartAngle(qreal startAngle);
75 void setPieStartAngle(qreal startAngle);
76 qreal startAngle() const;
76 qreal pieStartAngle() const;
77 void setEndAngle(qreal endAngle);
77 void setPieEndAngle(qreal endAngle);
78 qreal endAngle() const;
78 qreal pieEndAngle() const;
79
79
80 // convenience function
80 // convenience function
81 QPieSeries& operator << (QPieSlice* slice);
81 QPieSeries& operator << (QPieSlice* slice);
82 QPieSlice* add(qreal value, QString name);
82 QPieSlice* add(qreal value, QString name);
83 void setLabelsVisible(bool visible = true);
83 void setLabelsVisible(bool visible = true);
84
84
85 // TODO: find slices?
85 // TODO: find slices?
86 // QList<QPieSlice*> findByValue(qreal value);
86 // QList<QPieSlice*> findByValue(qreal value);
87 // ...
87 // ...
88
88
89 // TODO: sorting slices?
89 // TODO: sorting slices?
90 // void sort(QPieSeries::SortByValue|label|??)
90 // void sort(QPieSeries::SortByValue|label|??)
91
91
92 // TODO: general graphics customization
92 // TODO: general graphics customization
93 // setDrawStyle(2d|3d)
93 // setDrawStyle(2d|3d)
94 // setDropShadows
94 // setDropShadows
95
95
96 Q_SIGNALS:
96 Q_SIGNALS:
97
98 void changed(const QPieSeries::ChangeSet& changeSet);
99
100 void clicked(QPieSlice* slice);
97 void clicked(QPieSlice* slice);
101 void hoverEnter(QPieSlice* slice);
98 void hoverEnter(QPieSlice* slice);
102 void hoverLeave(QPieSlice* slice);
99 void hoverLeave(QPieSlice* slice);
103
100
104 void sizeFactorChanged();
101 void pieSizeChanged();
105 void positionChanged();
102 void piePositionChanged();
103
104 void changed(const QPieSeries::ChangeSet& changeSet); // TODO: hide this in PIMPL
106
105
107 private Q_SLOTS: // TODO: should be private and not visible in the interface at all
106 private Q_SLOTS: // TODO: should be private and not visible in the interface at all
108 void sliceChanged();
107 void sliceChanged();
109 void sliceClicked();
108 void sliceClicked();
110 void sliceHoverEnter();
109 void sliceHoverEnter();
111 void sliceHoverLeave();
110 void sliceHoverLeave();
112
111
113 private:
112 private:
114 void updateDerivativeData();
113 void updateDerivativeData();
115
114
116 private:
115 private:
117 Q_DISABLE_COPY(QPieSeries)
116 Q_DISABLE_COPY(QPieSeries)
118
117
119 // TODO: use PIML
118 // TODO: use PIML
120 friend class PiePresenter;
119 friend class PiePresenter;
121 friend class PieSlice;
120 friend class PieSlice;
122
121
123 QList<QPieSlice*> m_slices;
122 QList<QPieSlice*> m_slices;
124 qreal m_hPositionFactor;
123 qreal m_pieRelativeHorPos;
125 qreal m_vPositionFactor;
124 qreal m_pieRelativeVerPos;
126 qreal m_pieSizeFactor;
125 qreal m_pieRelativeSize;
127 qreal m_pieStartAngle;
126 qreal m_pieStartAngle;
128 qreal m_pieEndAngle;
127 qreal m_pieEndAngle;
129 qreal m_total;
128 qreal m_total;
130 };
129 };
131
130
132 QTCOMMERCIALCHART_END_NAMESPACE
131 QTCOMMERCIALCHART_END_NAMESPACE
133
132
134 #endif // PIESERIES_H
133 #endif // PIESERIES_H
General Comments 0
You need to be logged in to leave comments. Login now