##// END OF EJS Templates
Use labelBrush instead of labelPen for text labels
Tero Ahola -
r1307:7b3a3ea4ca65
parent child
Show More
@@ -1,331 +1,331
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20 #include "mainwidget.h"
20 #include "mainwidget.h"
21 #include "customslice.h"
21 #include "customslice.h"
22 #include "pentool.h"
22 #include "pentool.h"
23 #include "brushtool.h"
23 #include "brushtool.h"
24 #include <QPushButton>
24 #include <QPushButton>
25 #include <QComboBox>
25 #include <QComboBox>
26 #include <QCheckBox>
26 #include <QCheckBox>
27 #include <QLabel>
27 #include <QLabel>
28 #include <QGroupBox>
28 #include <QGroupBox>
29 #include <QDoubleSpinBox>
29 #include <QDoubleSpinBox>
30 #include <QFormLayout>
30 #include <QFormLayout>
31 #include <QFontDialog>
31 #include <QFontDialog>
32 #include <QChartView>
32 #include <QChartView>
33 #include <QPieSeries>
33 #include <QPieSeries>
34
34
35 QTCOMMERCIALCHART_USE_NAMESPACE
35 QTCOMMERCIALCHART_USE_NAMESPACE
36
36
37 MainWidget::MainWidget(QWidget* parent)
37 MainWidget::MainWidget(QWidget* parent)
38 :QWidget(parent),
38 :QWidget(parent),
39 m_slice(0)
39 m_slice(0)
40 {
40 {
41 // create chart
41 // create chart
42 QChart *chart = new QChart;
42 QChart *chart = new QChart;
43 chart->setTitle("Piechart customization");
43 chart->setTitle("Piechart customization");
44 chart->setAnimationOptions(QChart::AllAnimations);
44 chart->setAnimationOptions(QChart::AllAnimations);
45
45
46 // create series
46 // create series
47 m_series = new QPieSeries();
47 m_series = new QPieSeries();
48 *m_series << new CustomSlice("Slice 1", 10.0);
48 *m_series << new CustomSlice("Slice 1", 10.0);
49 *m_series << new CustomSlice("Slice 2", 20.0);
49 *m_series << new CustomSlice("Slice 2", 20.0);
50 *m_series << new CustomSlice("Slice 3", 30.0);
50 *m_series << new CustomSlice("Slice 3", 30.0);
51 *m_series << new CustomSlice("Slice 4", 40.0);
51 *m_series << new CustomSlice("Slice 4", 40.0);
52 *m_series << new CustomSlice("Slice 5", 50.0);
52 *m_series << new CustomSlice("Slice 5", 50.0);
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*)), this, SLOT(handleSliceClicked(QPieSlice*)));
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();
60 m_themeComboBox->addItem("Light", QChart::ChartThemeLight);
60 m_themeComboBox->addItem("Light", QChart::ChartThemeLight);
61 m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean);
61 m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean);
62 m_themeComboBox->addItem("Dark", QChart::ChartThemeDark);
62 m_themeComboBox->addItem("Dark", QChart::ChartThemeDark);
63 m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand);
63 m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand);
64 m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs);
64 m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs);
65 m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
65 m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
66 m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
66 m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
67
67
68 m_aaCheckBox = new QCheckBox();
68 m_aaCheckBox = new QCheckBox();
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();
72 m_legendCheckBox = new QCheckBox();
73
73
74 QFormLayout* chartSettingsLayout = new QFormLayout();
74 QFormLayout* chartSettingsLayout = new QFormLayout();
75 chartSettingsLayout->addRow("Theme", m_themeComboBox);
75 chartSettingsLayout->addRow("Theme", m_themeComboBox);
76 chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox);
76 chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox);
77 chartSettingsLayout->addRow("Animations", m_animationsCheckBox);
77 chartSettingsLayout->addRow("Animations", m_animationsCheckBox);
78 chartSettingsLayout->addRow("Legend", m_legendCheckBox);
78 chartSettingsLayout->addRow("Legend", m_legendCheckBox);
79 QGroupBox* chartSettings = new QGroupBox("Chart");
79 QGroupBox* chartSettings = new QGroupBox("Chart");
80 chartSettings->setLayout(chartSettingsLayout);
80 chartSettings->setLayout(chartSettingsLayout);
81
81
82 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings()));
82 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings()));
83 connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
83 connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
84 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()));
85 connect(m_legendCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
86
86
87 // series settings
87 // series settings
88 m_hPosition = new QDoubleSpinBox();
88 m_hPosition = new QDoubleSpinBox();
89 m_hPosition->setMinimum(0.0);
89 m_hPosition->setMinimum(0.0);
90 m_hPosition->setMaximum(1.0);
90 m_hPosition->setMaximum(1.0);
91 m_hPosition->setSingleStep(0.1);
91 m_hPosition->setSingleStep(0.1);
92 m_hPosition->setValue(m_series->horizontalPosition());
92 m_hPosition->setValue(m_series->horizontalPosition());
93
93
94 m_vPosition = new QDoubleSpinBox();
94 m_vPosition = new QDoubleSpinBox();
95 m_vPosition->setMinimum(0.0);
95 m_vPosition->setMinimum(0.0);
96 m_vPosition->setMaximum(1.0);
96 m_vPosition->setMaximum(1.0);
97 m_vPosition->setSingleStep(0.1);
97 m_vPosition->setSingleStep(0.1);
98 m_vPosition->setValue(m_series->verticalPosition());
98 m_vPosition->setValue(m_series->verticalPosition());
99
99
100 m_sizeFactor = new QDoubleSpinBox();
100 m_sizeFactor = new QDoubleSpinBox();
101 m_sizeFactor->setMinimum(0.0);
101 m_sizeFactor->setMinimum(0.0);
102 m_sizeFactor->setMaximum(1.0);
102 m_sizeFactor->setMaximum(1.0);
103 m_sizeFactor->setSingleStep(0.1);
103 m_sizeFactor->setSingleStep(0.1);
104 m_sizeFactor->setValue(m_series->pieSize());
104 m_sizeFactor->setValue(m_series->pieSize());
105
105
106 m_startAngle = new QDoubleSpinBox();
106 m_startAngle = new QDoubleSpinBox();
107 m_startAngle->setMinimum(-720);
107 m_startAngle->setMinimum(-720);
108 m_startAngle->setMaximum(720);
108 m_startAngle->setMaximum(720);
109 m_startAngle->setValue(m_series->pieStartAngle());
109 m_startAngle->setValue(m_series->pieStartAngle());
110 m_startAngle->setSingleStep(1);
110 m_startAngle->setSingleStep(1);
111
111
112 m_endAngle = new QDoubleSpinBox();
112 m_endAngle = new QDoubleSpinBox();
113 m_endAngle->setMinimum(-720);
113 m_endAngle->setMinimum(-720);
114 m_endAngle->setMaximum(720);
114 m_endAngle->setMaximum(720);
115 m_endAngle->setValue(m_series->pieEndAngle());
115 m_endAngle->setValue(m_series->pieEndAngle());
116 m_endAngle->setSingleStep(1);
116 m_endAngle->setSingleStep(1);
117
117
118 QPushButton *appendSlice = new QPushButton("Append slice");
118 QPushButton *appendSlice = new QPushButton("Append slice");
119 QPushButton *insertSlice = new QPushButton("Insert slice");
119 QPushButton *insertSlice = new QPushButton("Insert slice");
120
120
121 QFormLayout* seriesSettingsLayout = new QFormLayout();
121 QFormLayout* seriesSettingsLayout = new QFormLayout();
122 seriesSettingsLayout->addRow("Horizontal position", m_hPosition);
122 seriesSettingsLayout->addRow("Horizontal position", m_hPosition);
123 seriesSettingsLayout->addRow("Vertical position", m_vPosition);
123 seriesSettingsLayout->addRow("Vertical position", m_vPosition);
124 seriesSettingsLayout->addRow("Size factor", m_sizeFactor);
124 seriesSettingsLayout->addRow("Size factor", m_sizeFactor);
125 seriesSettingsLayout->addRow("Start angle", m_startAngle);
125 seriesSettingsLayout->addRow("Start angle", m_startAngle);
126 seriesSettingsLayout->addRow("End angle", m_endAngle);
126 seriesSettingsLayout->addRow("End angle", m_endAngle);
127 seriesSettingsLayout->addRow(appendSlice);
127 seriesSettingsLayout->addRow(appendSlice);
128 seriesSettingsLayout->addRow(insertSlice);
128 seriesSettingsLayout->addRow(insertSlice);
129 QGroupBox* seriesSettings = new QGroupBox("Series");
129 QGroupBox* seriesSettings = new QGroupBox("Series");
130 seriesSettings->setLayout(seriesSettingsLayout);
130 seriesSettings->setLayout(seriesSettingsLayout);
131
131
132 connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
132 connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
133 connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
133 connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
134 connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
134 connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
135 connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
135 connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
136 connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
136 connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
137 connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice()));
137 connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice()));
138 connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice()));
138 connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice()));
139
139
140 // slice settings
140 // slice settings
141 m_sliceName = new QLabel("<click a slice>");
141 m_sliceName = new QLabel("<click a slice>");
142 m_sliceValue = new QDoubleSpinBox();
142 m_sliceValue = new QDoubleSpinBox();
143 m_sliceValue->setMaximum(1000);
143 m_sliceValue->setMaximum(1000);
144 m_sliceLabelVisible = new QCheckBox();
144 m_sliceLabelVisible = new QCheckBox();
145 m_sliceLabelArmFactor = new QDoubleSpinBox();
145 m_sliceLabelArmFactor = new QDoubleSpinBox();
146 m_sliceLabelArmFactor->setSingleStep(0.01);
146 m_sliceLabelArmFactor->setSingleStep(0.01);
147 m_sliceExploded = new QCheckBox();
147 m_sliceExploded = new QCheckBox();
148 m_sliceExplodedFactor = new QDoubleSpinBox();
148 m_sliceExplodedFactor = new QDoubleSpinBox();
149 m_sliceExplodedFactor->setSingleStep(0.01);
149 m_sliceExplodedFactor->setSingleStep(0.01);
150 m_pen = new QPushButton();
150 m_pen = new QPushButton();
151 m_penTool = new PenTool("Slice pen", this);
151 m_penTool = new PenTool("Slice pen", this);
152 m_brush = new QPushButton();
152 m_brush = new QPushButton();
153 m_brushTool = new BrushTool("Slice brush", this);
153 m_brushTool = new BrushTool("Slice brush", this);
154 m_font = new QPushButton();
154 m_font = new QPushButton();
155 m_labelPen = new QPushButton();
155 m_labelBrush = new QPushButton();
156 m_labelPenTool = new PenTool("Label pen", this);
156 m_labelBrushTool = new BrushTool("Label brush", this);
157 QPushButton *removeSlice = new QPushButton("Remove slice");
157 QPushButton *removeSlice = new QPushButton("Remove slice");
158
158
159 QFormLayout* sliceSettingsLayout = new QFormLayout();
159 QFormLayout* sliceSettingsLayout = new QFormLayout();
160 sliceSettingsLayout->addRow("Selected", m_sliceName);
160 sliceSettingsLayout->addRow("Selected", m_sliceName);
161 sliceSettingsLayout->addRow("Value", m_sliceValue);
161 sliceSettingsLayout->addRow("Value", m_sliceValue);
162 sliceSettingsLayout->addRow("Pen", m_pen);
162 sliceSettingsLayout->addRow("Pen", m_pen);
163 sliceSettingsLayout->addRow("Brush", m_brush);
163 sliceSettingsLayout->addRow("Brush", m_brush);
164 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
164 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
165 sliceSettingsLayout->addRow("Label font", m_font);
165 sliceSettingsLayout->addRow("Label font", m_font);
166 sliceSettingsLayout->addRow("Label pen", m_labelPen);
166 sliceSettingsLayout->addRow("Label pen", m_labelBrush);
167 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
167 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
168 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
168 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
169 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
169 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
170 sliceSettingsLayout->addRow(removeSlice);
170 sliceSettingsLayout->addRow(removeSlice);
171 QGroupBox* sliceSettings = new QGroupBox("Slice");
171 QGroupBox* sliceSettings = new QGroupBox("Slice");
172 sliceSettings->setLayout(sliceSettingsLayout);
172 sliceSettings->setLayout(sliceSettingsLayout);
173
173
174 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
174 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
175 connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show()));
175 connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show()));
176 connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
176 connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
177 connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show()));
177 connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show()));
178 connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
178 connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
179 connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog()));
179 connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog()));
180 connect(m_labelPen, SIGNAL(clicked()), m_labelPenTool, SLOT(show()));
180 connect(m_labelBrush, SIGNAL(clicked()), m_labelBrushTool, SLOT(show()));
181 connect(m_labelPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
181 connect(m_labelBrushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
182 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
182 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
183 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
183 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
184 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
184 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
185 connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
185 connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
186 connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
186 connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
187 connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice()));
187 connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice()));
188
188
189 // create chart view
189 // create chart view
190 m_chartView = new QChartView(chart);
190 m_chartView = new QChartView(chart);
191
191
192 // create main layout
192 // create main layout
193 QVBoxLayout *settingsLayout = new QVBoxLayout();
193 QVBoxLayout *settingsLayout = new QVBoxLayout();
194 settingsLayout->addWidget(chartSettings);
194 settingsLayout->addWidget(chartSettings);
195 settingsLayout->addWidget(seriesSettings);
195 settingsLayout->addWidget(seriesSettings);
196 settingsLayout->addWidget(sliceSettings);
196 settingsLayout->addWidget(sliceSettings);
197 settingsLayout->addStretch();
197 settingsLayout->addStretch();
198
198
199 QGridLayout* baseLayout = new QGridLayout();
199 QGridLayout* baseLayout = new QGridLayout();
200 baseLayout->addLayout(settingsLayout, 0, 0);
200 baseLayout->addLayout(settingsLayout, 0, 0);
201 baseLayout->addWidget(m_chartView, 0, 1);
201 baseLayout->addWidget(m_chartView, 0, 1);
202 setLayout(baseLayout);
202 setLayout(baseLayout);
203
203
204 updateSerieSettings();
204 updateSerieSettings();
205 }
205 }
206
206
207
207
208 void MainWidget::updateChartSettings()
208 void MainWidget::updateChartSettings()
209 {
209 {
210 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
210 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
211 m_chartView->chart()->setTheme(theme);
211 m_chartView->chart()->setTheme(theme);
212 m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked());
212 m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked());
213
213
214 if (m_animationsCheckBox->checkState() == Qt::Checked)
214 if (m_animationsCheckBox->checkState() == Qt::Checked)
215 m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
215 m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
216 else
216 else
217 m_chartView->chart()->setAnimationOptions(QChart::NoAnimation);
217 m_chartView->chart()->setAnimationOptions(QChart::NoAnimation);
218
218
219 if (m_legendCheckBox->checkState() == Qt::Checked)
219 if (m_legendCheckBox->checkState() == Qt::Checked)
220 m_chartView->chart()->legend()->show();
220 m_chartView->chart()->legend()->show();
221 else
221 else
222 m_chartView->chart()->legend()->hide();
222 m_chartView->chart()->legend()->hide();
223 }
223 }
224
224
225 void MainWidget::updateSerieSettings()
225 void MainWidget::updateSerieSettings()
226 {
226 {
227 m_series->setHorizontalPosition(m_hPosition->value());
227 m_series->setHorizontalPosition(m_hPosition->value());
228 m_series->setVerticalPosition(m_vPosition->value());
228 m_series->setVerticalPosition(m_vPosition->value());
229 m_series->setPieSize(m_sizeFactor->value());
229 m_series->setPieSize(m_sizeFactor->value());
230 m_series->setPieStartAngle(m_startAngle->value());
230 m_series->setPieStartAngle(m_startAngle->value());
231 m_series->setPieEndAngle(m_endAngle->value());
231 m_series->setPieEndAngle(m_endAngle->value());
232 }
232 }
233
233
234 void MainWidget::updateSliceSettings()
234 void MainWidget::updateSliceSettings()
235 {
235 {
236 if (!m_slice)
236 if (!m_slice)
237 return;
237 return;
238
238
239 m_slice->setValue(m_sliceValue->value());
239 m_slice->setValue(m_sliceValue->value());
240
240
241 m_slice->setPen(m_penTool->pen());
241 m_slice->setPen(m_penTool->pen());
242 m_slice->setBrush(m_brushTool->brush());
242 m_slice->setBrush(m_brushTool->brush());
243
243
244 m_slice->setLabelPen(m_labelPenTool->pen());
244 m_slice->setLabelBrush(m_labelBrushTool->brush());
245 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
245 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
246 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
246 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
247
247
248 m_slice->setExploded(m_sliceExploded->isChecked());
248 m_slice->setExploded(m_sliceExploded->isChecked());
249 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
249 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
250 }
250 }
251
251
252 void MainWidget::handleSliceClicked(QPieSlice* slice)
252 void MainWidget::handleSliceClicked(QPieSlice* slice)
253 {
253 {
254 m_slice = static_cast<CustomSlice*>(slice);
254 m_slice = static_cast<CustomSlice*>(slice);
255
255
256 // name
256 // name
257 m_sliceName->setText(slice->label());
257 m_sliceName->setText(slice->label());
258
258
259 // value
259 // value
260 m_sliceValue->blockSignals(true);
260 m_sliceValue->blockSignals(true);
261 m_sliceValue->setValue(slice->value());
261 m_sliceValue->setValue(slice->value());
262 m_sliceValue->blockSignals(false);
262 m_sliceValue->blockSignals(false);
263
263
264 // pen
264 // pen
265 m_pen->setText(PenTool::name(m_slice->pen()));
265 m_pen->setText(PenTool::name(m_slice->pen()));
266 m_penTool->setPen(m_slice->pen());
266 m_penTool->setPen(m_slice->pen());
267
267
268 // brush
268 // brush
269 m_brush->setText(m_slice->originalBrush().color().name());
269 m_brush->setText(m_slice->originalBrush().color().name());
270 m_brushTool->setBrush(m_slice->originalBrush());
270 m_brushTool->setBrush(m_slice->originalBrush());
271
271
272 // label
272 // label
273 m_labelPen->setText(PenTool::name(m_slice->labelPen()));
273 m_labelBrush->setText(BrushTool::name(m_slice->labelBrush()));
274 m_labelPenTool->setPen(m_slice->labelPen());
274 m_labelBrushTool->setBrush(m_slice->labelBrush());
275 m_font->setText(slice->labelFont().toString());
275 m_font->setText(slice->labelFont().toString());
276 m_sliceLabelVisible->blockSignals(true);
276 m_sliceLabelVisible->blockSignals(true);
277 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
277 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
278 m_sliceLabelVisible->blockSignals(false);
278 m_sliceLabelVisible->blockSignals(false);
279 m_sliceLabelArmFactor->blockSignals(true);
279 m_sliceLabelArmFactor->blockSignals(true);
280 m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor());
280 m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor());
281 m_sliceLabelArmFactor->blockSignals(false);
281 m_sliceLabelArmFactor->blockSignals(false);
282
282
283 // exploded
283 // exploded
284 m_sliceExploded->blockSignals(true);
284 m_sliceExploded->blockSignals(true);
285 m_sliceExploded->setChecked(slice->isExploded());
285 m_sliceExploded->setChecked(slice->isExploded());
286 m_sliceExploded->blockSignals(false);
286 m_sliceExploded->blockSignals(false);
287 m_sliceExplodedFactor->blockSignals(true);
287 m_sliceExplodedFactor->blockSignals(true);
288 m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor());
288 m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor());
289 m_sliceExplodedFactor->blockSignals(false);
289 m_sliceExplodedFactor->blockSignals(false);
290 }
290 }
291
291
292 void MainWidget::showFontDialog()
292 void MainWidget::showFontDialog()
293 {
293 {
294 if (!m_slice)
294 if (!m_slice)
295 return;
295 return;
296
296
297 QFontDialog dialog(m_slice->labelFont());
297 QFontDialog dialog(m_slice->labelFont());
298 dialog.show();
298 dialog.show();
299 dialog.exec();
299 dialog.exec();
300
300
301 m_slice->setLabelFont(dialog.currentFont());
301 m_slice->setLabelFont(dialog.currentFont());
302 m_font->setText(dialog.currentFont().toString());
302 m_font->setText(dialog.currentFont().toString());
303 }
303 }
304
304
305 void MainWidget::appendSlice()
305 void MainWidget::appendSlice()
306 {
306 {
307 *m_series << new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0);
307 *m_series << new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0);
308 }
308 }
309
309
310 void MainWidget::insertSlice()
310 void MainWidget::insertSlice()
311 {
311 {
312 if (!m_slice)
312 if (!m_slice)
313 return;
313 return;
314
314
315 int i = m_series->slices().indexOf(m_slice);
315 int i = m_series->slices().indexOf(m_slice);
316
316
317 m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0));
317 m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0));
318 }
318 }
319
319
320 void MainWidget::removeSlice()
320 void MainWidget::removeSlice()
321 {
321 {
322 if (!m_slice)
322 if (!m_slice)
323 return;
323 return;
324
324
325 m_sliceName->setText("<click a slice>");
325 m_sliceName->setText("<click a slice>");
326
326
327 m_series->remove(m_slice);
327 m_series->remove(m_slice);
328 m_slice = 0;
328 m_slice = 0;
329 }
329 }
330
330
331 #include "moc_mainwidget.cpp"
331 #include "moc_mainwidget.cpp"
@@ -1,91 +1,91
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20 #ifndef MAINWIDGET_H
20 #ifndef MAINWIDGET_H
21 #define MAINWIDGET_H
21 #define MAINWIDGET_H
22
22
23 #include <QWidget>
23 #include <QWidget>
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25
25
26 class QLabel;
26 class QLabel;
27 class QPushButton;
27 class QPushButton;
28 class QCheckBox;
28 class QCheckBox;
29 class QComboBox;
29 class QComboBox;
30 class QDoubleSpinBox;
30 class QDoubleSpinBox;
31 class PenTool;
31 class PenTool;
32 class BrushTool;
32 class BrushTool;
33 class CustomSlice;
33 class CustomSlice;
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 class QChartView;
36 class QChartView;
37 class QPieSeries;
37 class QPieSeries;
38 class QPieSlice;
38 class QPieSlice;
39 QTCOMMERCIALCHART_END_NAMESPACE
39 QTCOMMERCIALCHART_END_NAMESPACE
40
40
41 QTCOMMERCIALCHART_USE_NAMESPACE
41 QTCOMMERCIALCHART_USE_NAMESPACE
42
42
43 class MainWidget : public QWidget
43 class MainWidget : public QWidget
44 {
44 {
45 Q_OBJECT
45 Q_OBJECT
46
46
47 public:
47 public:
48 explicit MainWidget(QWidget* parent = 0);
48 explicit MainWidget(QWidget* parent = 0);
49
49
50 public Q_SLOTS:
50 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);
54 void handleSliceClicked(QPieSlice* slice);
55 void showFontDialog();
55 void showFontDialog();
56 void appendSlice();
56 void appendSlice();
57 void insertSlice();
57 void insertSlice();
58 void removeSlice();
58 void removeSlice();
59
59
60 private:
60 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 QCheckBox *m_legendCheckBox;
65
65
66 QChartView* m_chartView;
66 QChartView* m_chartView;
67 QPieSeries* m_series;
67 QPieSeries* m_series;
68 CustomSlice* m_slice;
68 CustomSlice* m_slice;
69
69
70 QDoubleSpinBox* m_hPosition;
70 QDoubleSpinBox* m_hPosition;
71 QDoubleSpinBox* m_vPosition;
71 QDoubleSpinBox* m_vPosition;
72 QDoubleSpinBox* m_sizeFactor;
72 QDoubleSpinBox* m_sizeFactor;
73 QDoubleSpinBox* m_startAngle;
73 QDoubleSpinBox* m_startAngle;
74 QDoubleSpinBox* m_endAngle;
74 QDoubleSpinBox* m_endAngle;
75
75
76 QLabel* m_sliceName;
76 QLabel* m_sliceName;
77 QDoubleSpinBox* m_sliceValue;
77 QDoubleSpinBox* m_sliceValue;
78 QCheckBox* m_sliceLabelVisible;
78 QCheckBox* m_sliceLabelVisible;
79 QDoubleSpinBox* m_sliceLabelArmFactor;
79 QDoubleSpinBox* m_sliceLabelArmFactor;
80 QCheckBox* m_sliceExploded;
80 QCheckBox* m_sliceExploded;
81 QDoubleSpinBox* m_sliceExplodedFactor;
81 QDoubleSpinBox* m_sliceExplodedFactor;
82 QPushButton *m_brush;
82 QPushButton *m_brush;
83 BrushTool *m_brushTool;
83 BrushTool *m_brushTool;
84 QPushButton *m_pen;
84 QPushButton *m_pen;
85 PenTool *m_penTool;
85 PenTool *m_penTool;
86 QPushButton *m_font;
86 QPushButton *m_font;
87 QPushButton *m_labelPen;
87 QPushButton *m_labelBrush;
88 PenTool *m_labelPenTool;
88 BrushTool *m_labelBrushTool;
89 };
89 };
90
90
91 #endif // MAINWIDGET_H
91 #endif // MAINWIDGET_H
@@ -1,149 +1,150
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativepieseries.h"
21 #include "declarativepieseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include <qdeclarativelist.h>
24 #include <qdeclarativelist.h>
25 #include <QVPieModelMapper>
25 #include <QVPieModelMapper>
26 #include <QHPieModelMapper>
26 #include <QHPieModelMapper>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 DeclarativePieSlice::DeclarativePieSlice(QObject *parent) :
30 DeclarativePieSlice::DeclarativePieSlice(QObject *parent) :
31 QPieSlice(parent)
31 QPieSlice(parent)
32 {
32 {
33 }
33 }
34
34
35 QColor DeclarativePieSlice::color()
35 QColor DeclarativePieSlice::color()
36 {
36 {
37 return brush().color();
37 return brush().color();
38 }
38 }
39
39
40 void DeclarativePieSlice::setColor(QColor color)
40 void DeclarativePieSlice::setColor(QColor color)
41 {
41 {
42 QBrush b = brush();
42 QBrush b = brush();
43 b.setColor(color);
43 b.setColor(color);
44 setBrush(b);
44 setBrush(b);
45 }
45 }
46
46
47 QColor DeclarativePieSlice::borderColor()
47 QColor DeclarativePieSlice::borderColor()
48 {
48 {
49 return pen().color();
49 return pen().color();
50 }
50 }
51
51
52 void DeclarativePieSlice::setBorderColor(QColor color)
52 void DeclarativePieSlice::setBorderColor(QColor color)
53 {
53 {
54 QPen p = pen();
54 QPen p = pen();
55 p.setColor(color);
55 p.setColor(color);
56 setPen(p);
56 setPen(p);
57 }
57 }
58
58
59 int DeclarativePieSlice::borderWidth()
59 int DeclarativePieSlice::borderWidth()
60 {
60 {
61 return pen().width();
61 return pen().width();
62 }
62 }
63
63
64 void DeclarativePieSlice::setBorderWidth(int width)
64 void DeclarativePieSlice::setBorderWidth(int width)
65 {
65 {
66 QPen p = pen();
66 QPen p = pen();
67 p.setWidth(width);
67 p.setWidth(width);
68 setPen(p);
68 setPen(p);
69 }
69 }
70
70
71 QColor DeclarativePieSlice::labelColor()
71 QColor DeclarativePieSlice::labelColor()
72 {
72 {
73 return labelPen().color();
73 return labelBrush().color();
74 }
74 }
75
75
76 void DeclarativePieSlice::setLabelColor(QColor color)
76 void DeclarativePieSlice::setLabelColor(QColor color)
77 {
77 {
78 QPen p = labelPen();
78 // TODO: use brush instead for label color
79 p.setColor(color);
79 QBrush b = labelBrush();
80 setLabelPen(p);
80 b.setColor(color);
81 setLabelBrush(b);
81 }
82 }
82
83
83 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
84 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
84 QPieSeries(parent)
85 QPieSeries(parent)
85 {
86 {
86 }
87 }
87
88
88 void DeclarativePieSeries::classBegin()
89 void DeclarativePieSeries::classBegin()
89 {
90 {
90 }
91 }
91
92
92 void DeclarativePieSeries::componentComplete()
93 void DeclarativePieSeries::componentComplete()
93 {
94 {
94 foreach(QObject *child, children()) {
95 foreach(QObject *child, children()) {
95 if (qobject_cast<DeclarativePieSlice *>(child)) {
96 if (qobject_cast<DeclarativePieSlice *>(child)) {
96 QPieSeries::append(qobject_cast<DeclarativePieSlice *>(child));
97 QPieSeries::append(qobject_cast<DeclarativePieSlice *>(child));
97 } else if(qobject_cast<QVPieModelMapper *>(child)) {
98 } else if(qobject_cast<QVPieModelMapper *>(child)) {
98 QVPieModelMapper *mapper = qobject_cast<QVPieModelMapper *>(child);
99 QVPieModelMapper *mapper = qobject_cast<QVPieModelMapper *>(child);
99 mapper->setSeries(this);
100 mapper->setSeries(this);
100 } else if(qobject_cast<QHPieModelMapper *>(child)) {
101 } else if(qobject_cast<QHPieModelMapper *>(child)) {
101 QHPieModelMapper *mapper = qobject_cast<QHPieModelMapper *>(child);
102 QHPieModelMapper *mapper = qobject_cast<QHPieModelMapper *>(child);
102 mapper->setSeries(this);
103 mapper->setSeries(this);
103 }
104 }
104 }
105 }
105 }
106 }
106
107
107 QDeclarativeListProperty<QObject> DeclarativePieSeries::seriesChildren()
108 QDeclarativeListProperty<QObject> DeclarativePieSeries::seriesChildren()
108 {
109 {
109 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativePieSeries::appendSeriesChildren);
110 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativePieSeries::appendSeriesChildren);
110 }
111 }
111
112
112 void DeclarativePieSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
113 void DeclarativePieSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
113 {
114 {
114 // Empty implementation; the children are parsed in componentComplete instead
115 // Empty implementation; the children are parsed in componentComplete instead
115 Q_UNUSED(list);
116 Q_UNUSED(list);
116 Q_UNUSED(element);
117 Q_UNUSED(element);
117 }
118 }
118
119
119 DeclarativePieSlice *DeclarativePieSeries::at(int index)
120 DeclarativePieSlice *DeclarativePieSeries::at(int index)
120 {
121 {
121 QList<QPieSlice*> sliceList = slices();
122 QList<QPieSlice*> sliceList = slices();
122 if (index < sliceList.count())
123 if (index < sliceList.count())
123 return qobject_cast<DeclarativePieSlice *>(sliceList[index]);
124 return qobject_cast<DeclarativePieSlice *>(sliceList[index]);
124
125
125 return 0;
126 return 0;
126 }
127 }
127
128
128 DeclarativePieSlice* DeclarativePieSeries::find(QString label)
129 DeclarativePieSlice* DeclarativePieSeries::find(QString label)
129 {
130 {
130 foreach (QPieSlice *slice, slices()) {
131 foreach (QPieSlice *slice, slices()) {
131 if (slice->label() == label)
132 if (slice->label() == label)
132 return qobject_cast<DeclarativePieSlice *>(slice);
133 return qobject_cast<DeclarativePieSlice *>(slice);
133 }
134 }
134 return 0;
135 return 0;
135 }
136 }
136
137
137 DeclarativePieSlice* DeclarativePieSeries::append(QString label, qreal value)
138 DeclarativePieSlice* DeclarativePieSeries::append(QString label, qreal value)
138 {
139 {
139 // TODO: parameter order is wrong, switch it:
140 // TODO: parameter order is wrong, switch it:
140 DeclarativePieSlice *slice = new DeclarativePieSlice(this);
141 DeclarativePieSlice *slice = new DeclarativePieSlice(this);
141 slice->setLabel(label);
142 slice->setLabel(label);
142 slice->setValue(value);
143 slice->setValue(value);
143 QPieSeries::append(slice);
144 QPieSeries::append(slice);
144 return slice;
145 return slice;
145 }
146 }
146
147
147 #include "moc_declarativepieseries.cpp"
148 #include "moc_declarativepieseries.cpp"
148
149
149 QTCOMMERCIALCHART_END_NAMESPACE
150 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,342 +1,323
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarset.h"
21 #include "qbarset.h"
22 #include "qbarset_p.h"
22 #include "qbarset_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QBarSet
27 \class QBarSet
28 \brief part of QtCommercial chart API.
28 \brief part of QtCommercial chart API.
29
29
30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
31 First value of set is assumed to belong to first category, second to second category and so on.
31 First value of set is assumed to belong to first category, second to second category and so on.
32 If set has fewer values than there are categories, then the missing values are assumed to be
32 If set has fewer values than there are categories, then the missing values are assumed to be
33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
34
34
35 \mainclass
35 \mainclass
36
36
37 \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries
37 \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries
38 */
38 */
39
39
40 /*!
40 /*!
41 \fn void QBarSet::clicked(QString category)
41 \fn void QBarSet::clicked(QString category)
42 \brief signals that set has been clicked
42 \brief signals that set has been clicked
43 Parameter \a category describes on which category was clicked
43 Parameter \a category describes on which category was clicked
44 */
44 */
45
45
46 /*!
46 /*!
47 \fn void QBarSet::hovered(bool status)
47 \fn void QBarSet::hovered(bool status)
48 \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left.
48 \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left.
49
49
50 The signal is emitted if mouse is hovered on top of set
50 The signal is emitted if mouse is hovered on top of set
51 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
51 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
52 */
52 */
53
53
54 /*!
54 /*!
55 Constructs QBarSet with a name of \a name and with parent of \a parent
55 Constructs QBarSet with a name of \a name and with parent of \a parent
56 */
56 */
57 QBarSet::QBarSet(const QString name, QObject *parent)
57 QBarSet::QBarSet(const QString name, QObject *parent)
58 : QObject(parent)
58 : QObject(parent)
59 ,d_ptr(new QBarSetPrivate(name,this))
59 ,d_ptr(new QBarSetPrivate(name,this))
60 {
60 {
61 }
61 }
62
62
63 /*!
63 /*!
64 Destroys the barset
64 Destroys the barset
65 */
65 */
66 QBarSet::~QBarSet()
66 QBarSet::~QBarSet()
67 {
67 {
68 // NOTE: d_ptr destroyed by QObject
68 // NOTE: d_ptr destroyed by QObject
69 }
69 }
70
70
71 /*!
71 /*!
72 Sets new \a name for set.
72 Sets new \a name for set.
73 */
73 */
74 void QBarSet::setName(const QString name)
74 void QBarSet::setName(const QString name)
75 {
75 {
76 d_ptr->m_name = name;
76 d_ptr->m_name = name;
77 }
77 }
78
78
79 /*!
79 /*!
80 Returns name of the set.
80 Returns name of the set.
81 */
81 */
82 QString QBarSet::name() const
82 QString QBarSet::name() const
83 {
83 {
84 return d_ptr->m_name;
84 return d_ptr->m_name;
85 }
85 }
86
86
87 /*!
87 /*!
88 Appends a point to set. Parameter \a value x coordinate defines the
88 Appends a point to set. Parameter \a value x coordinate defines the
89 position in x-axis and y coordinate defines the height of bar.
89 position in x-axis and y coordinate defines the height of bar.
90 Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries)
90 Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries)
91 the x values are used or ignored.
91 the x values are used or ignored.
92 */
92 */
93 void QBarSet::append(const QPointF value)
93 void QBarSet::append(const QPointF value)
94 {
94 {
95 d_ptr->m_values.append(value);
95 d_ptr->m_values.append(value);
96 emit d_ptr->restructuredBars();
96 emit d_ptr->restructuredBars();
97 }
97 }
98
98
99 /*!
99 /*!
100 Appends a list of \a values to set. Works like append with single point.
100 Appends a list of \a values to set. Works like append with single point.
101 \sa append()
101 \sa append()
102 */
102 */
103 void QBarSet::append(const QList<QPointF> values)
103 void QBarSet::append(const QList<QPointF> values)
104 {
104 {
105 for (int i=0; i<values.count(); i++) {
105 for (int i=0; i<values.count(); i++) {
106 d_ptr->m_values.append(values.at(i));
106 d_ptr->m_values.append(values.at(i));
107 }
107 }
108 emit d_ptr->restructuredBars();
108 emit d_ptr->restructuredBars();
109 }
109 }
110
110
111 /*!
111 /*!
112 Appends new value \a value to the end of set. Internally the value is converted to QPointF,
112 Appends new value \a value to the end of set. Internally the value is converted to QPointF,
113 with x coordinate being the index of appended value and y coordinate is the value.
113 with x coordinate being the index of appended value and y coordinate is the value.
114 */
114 */
115 void QBarSet::append(const qreal value)
115 void QBarSet::append(const qreal value)
116 {
116 {
117 append(QPointF(d_ptr->m_values.count(), value));
117 append(QPointF(d_ptr->m_values.count(), value));
118 }
118 }
119
119
120 /*!
120 /*!
121 Appends a list of reals to set. Works like append with single real value. The values in list
121 Appends a list of reals to set. Works like append with single real value. The values in list
122 are converted to QPointF, where x coordinate is the index of point and y coordinate is the value.
122 are converted to QPointF, where x coordinate is the index of point and y coordinate is the value.
123 \sa append()
123 \sa append()
124 */
124 */
125 void QBarSet::append(const QList<qreal> values)
125 void QBarSet::append(const QList<qreal> values)
126 {
126 {
127 int index = d_ptr->m_values.count();
127 int index = d_ptr->m_values.count();
128 for (int i=0; i<values.count(); i++) {
128 for (int i=0; i<values.count(); i++) {
129 d_ptr->m_values.append(QPointF(index,values.at(i)));
129 d_ptr->m_values.append(QPointF(index,values.at(i)));
130 index++;
130 index++;
131 }
131 }
132 emit d_ptr->restructuredBars();
132 emit d_ptr->restructuredBars();
133 }
133 }
134
134
135 /*!
135 /*!
136 Convinience operator. Same as append, with real \a value.
136 Convinience operator. Same as append, with real \a value.
137 \sa append()
137 \sa append()
138 */
138 */
139 QBarSet& QBarSet::operator << (const qreal &value)
139 QBarSet& QBarSet::operator << (const qreal &value)
140 {
140 {
141 append(value);
141 append(value);
142 return *this;
142 return *this;
143 }
143 }
144
144
145 /*!
145 /*!
146 Convinience operator. Same as append, with QPointF \a value.
146 Convinience operator. Same as append, with QPointF \a value.
147 \sa append()
147 \sa append()
148 */
148 */
149 QBarSet& QBarSet::operator << (const QPointF &value)
149 QBarSet& QBarSet::operator << (const QPointF &value)
150 {
150 {
151 append(value);
151 append(value);
152 return *this;
152 return *this;
153 }
153 }
154
154
155 /*!
155 /*!
156 Inserts new \a value on the \a index position.
156 Inserts new \a value on the \a index position.
157 The value that is currently at this postion is moved to postion index + 1
157 The value that is currently at this postion is moved to postion index + 1
158 \sa remove()
158 \sa remove()
159 */
159 */
160 void QBarSet::insert(const int index, const qreal value)
160 void QBarSet::insert(const int index, const qreal value)
161 {
161 {
162 d_ptr->m_values.insert(index, QPointF(index, value));
162 d_ptr->m_values.insert(index, QPointF(index, value));
163 // emit d_ptr->updatedBars();
163 // emit d_ptr->updatedBars();
164 }
164 }
165
165
166 /*!
166 /*!
167 Removes the value specified by \a index
167 Removes the value specified by \a index
168 \sa insert()
168 \sa insert()
169 */
169 */
170 void QBarSet::remove(const int index)
170 void QBarSet::remove(const int index)
171 {
171 {
172 d_ptr->m_values.removeAt(index);
172 d_ptr->m_values.removeAt(index);
173 // emit d_ptr->updatedBars();
173 // emit d_ptr->updatedBars();
174 }
174 }
175
175
176 /*!
176 /*!
177 Sets a new value \a value to set, indexed by \a index
177 Sets a new value \a value to set, indexed by \a index
178 */
178 */
179 void QBarSet::replace(const int index, const qreal value)
179 void QBarSet::replace(const int index, const qreal value)
180 {
180 {
181 d_ptr->m_values.replace(index,QPointF(index,value));
181 d_ptr->m_values.replace(index,QPointF(index,value));
182 emit d_ptr->updatedBars();
182 emit d_ptr->updatedBars();
183 }
183 }
184
184
185 /*!
185 /*!
186 Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF.
186 Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF.
187 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
187 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
188 of the QPointF (if appended with QPointF append).
188 of the QPointF (if appended with QPointF append).
189 If the index is out of bounds QPointF(0, 0.0) is returned.
189 If the index is out of bounds QPointF(0, 0.0) is returned.
190 */
190 */
191 QPointF QBarSet::at(const int index) const
191 QPointF QBarSet::at(const int index) const
192 {
192 {
193 if (index < 0 || index >= d_ptr->m_values.count()) {
193 if (index < 0 || index >= d_ptr->m_values.count()) {
194 return QPointF(index, 0.0);
194 return QPointF(index, 0.0);
195 }
195 }
196
196
197 return d_ptr->m_values.at(index);
197 return d_ptr->m_values.at(index);
198 }
198 }
199
199
200 /*!
200 /*!
201 Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF.
201 Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF.
202 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
202 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
203 of the QPointF (if appended with QPointF append).
203 of the QPointF (if appended with QPointF append).
204 */
204 */
205 QPointF QBarSet::operator [](const int index) const
205 QPointF QBarSet::operator [](const int index) const
206 {
206 {
207 return d_ptr->m_values.at(index);
207 return d_ptr->m_values.at(index);
208 }
208 }
209
209
210 /*!
210 /*!
211 Returns count of values in set.
211 Returns count of values in set.
212 */
212 */
213 int QBarSet::count() const
213 int QBarSet::count() const
214 {
214 {
215 return d_ptr->m_values.count();
215 return d_ptr->m_values.count();
216 }
216 }
217
217
218 /*!
218 /*!
219 Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation.
219 Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation.
220 */
220 */
221 qreal QBarSet::sum() const
221 qreal QBarSet::sum() const
222 {
222 {
223 qreal total(0);
223 qreal total(0);
224 for (int i=0; i < d_ptr->m_values.count(); i++) {
224 for (int i=0; i < d_ptr->m_values.count(); i++) {
225 //total += d_ptr->m_values.at(i);
225 //total += d_ptr->m_values.at(i);
226 total += d_ptr->m_values.at(i).y();
226 total += d_ptr->m_values.at(i).y();
227 }
227 }
228 return total;
228 return total;
229 }
229 }
230
230
231 /*!
231 /*!
232 Sets pen for set. Bars of this set are drawn using \a pen
232 Sets pen for set. Bars of this set are drawn using \a pen
233 */
233 */
234 void QBarSet::setPen(const QPen &pen)
234 void QBarSet::setPen(const QPen &pen)
235 {
235 {
236 if(d_ptr->m_pen!=pen){
236 if(d_ptr->m_pen!=pen){
237 d_ptr->m_pen = pen;
237 d_ptr->m_pen = pen;
238 emit d_ptr->updatedBars();
238 emit d_ptr->updatedBars();
239 }
239 }
240 }
240 }
241
241
242 /*!
242 /*!
243 Returns pen of the set.
243 Returns pen of the set.
244 */
244 */
245 QPen QBarSet::pen() const
245 QPen QBarSet::pen() const
246 {
246 {
247 return d_ptr->m_pen;
247 return d_ptr->m_pen;
248 }
248 }
249
249
250 /*!
250 /*!
251 Sets brush for the set. Bars of this set are drawn using \a brush
251 Sets brush for the set. Bars of this set are drawn using \a brush
252 */
252 */
253 void QBarSet::setBrush(const QBrush &brush)
253 void QBarSet::setBrush(const QBrush &brush)
254 {
254 {
255 if(d_ptr->m_brush!=brush){
255 if(d_ptr->m_brush!=brush){
256 d_ptr->m_brush = brush;
256 d_ptr->m_brush = brush;
257 emit d_ptr->updatedBars();
257 emit d_ptr->updatedBars();
258 }
258 }
259 }
259 }
260
260
261 /*!
261 /*!
262 Returns brush of the set.
262 Returns brush of the set.
263 */
263 */
264 QBrush QBarSet::brush() const
264 QBrush QBarSet::brush() const
265 {
265 {
266 return d_ptr->m_brush;
266 return d_ptr->m_brush;
267 }
267 }
268
268
269 /*!
269 /*!
270 Sets \a pen of the values that are drawn on top of this barset
271 */
272 void QBarSet::setLabelPen(const QPen &pen)
273 {
274 if(d_ptr->m_labelPen!=pen){
275 d_ptr->m_labelPen = pen;
276 emit d_ptr->updatedBars();
277 }
278 }
279
280 /*!
281 Returns pen of the values that are drawn on top of this barset
282 */
283 QPen QBarSet::labelPen() const
284 {
285 return d_ptr->m_labelPen;
286 }
287
288 /*!
289 Sets \a brush of the values that are drawn on top of this barset
270 Sets \a brush of the values that are drawn on top of this barset
290 */
271 */
291 void QBarSet::setLabelBrush(const QBrush &brush)
272 void QBarSet::setLabelBrush(const QBrush &brush)
292 {
273 {
293 if(d_ptr->m_labelBrush!=brush){
274 if(d_ptr->m_labelBrush!=brush){
294 d_ptr->m_labelBrush = brush;
275 d_ptr->m_labelBrush = brush;
295 emit d_ptr->updatedBars();
276 emit d_ptr->updatedBars();
296 }
277 }
297 }
278 }
298
279
299 /*!
280 /*!
300 Returns brush of the values that are drawn on top of this barset
281 Returns brush of the values that are drawn on top of this barset
301 */
282 */
302 QBrush QBarSet::labelBrush() const
283 QBrush QBarSet::labelBrush() const
303 {
284 {
304 return d_ptr->m_labelBrush;
285 return d_ptr->m_labelBrush;
305 }
286 }
306
287
307 /*!
288 /*!
308 Sets the \a font for values that are drawn on top of this barset
289 Sets the \a font for values that are drawn on top of this barset
309 */
290 */
310 void QBarSet::setLabelFont(const QFont &font)
291 void QBarSet::setLabelFont(const QFont &font)
311 {
292 {
312 if(d_ptr->m_labelFont!=font) {
293 if(d_ptr->m_labelFont!=font) {
313 d_ptr->m_labelFont = font;
294 d_ptr->m_labelFont = font;
314 emit d_ptr->updatedBars();
295 emit d_ptr->updatedBars();
315 }
296 }
316
297
317 }
298 }
318
299
319 /*!
300 /*!
320 Returns the pen for values that are drawn on top of this set
301 Returns the pen for values that are drawn on top of this set
321 */
302 */
322 QFont QBarSet::labelFont() const
303 QFont QBarSet::labelFont() const
323 {
304 {
324 return d_ptr->m_labelFont;
305 return d_ptr->m_labelFont;
325 }
306 }
326
307
327 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
308 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
328
309
329 QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent),
310 QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent),
330 q_ptr(parent),
311 q_ptr(parent),
331 m_name(name)
312 m_name(name)
332 {
313 {
333 }
314 }
334
315
335 QBarSetPrivate::~QBarSetPrivate()
316 QBarSetPrivate::~QBarSetPrivate()
336 {
317 {
337 }
318 }
338
319
339 #include "moc_qbarset.cpp"
320 #include "moc_qbarset.cpp"
340 #include "moc_qbarset_p.cpp"
321 #include "moc_qbarset_p.cpp"
341
322
342 QTCOMMERCIALCHART_END_NAMESPACE
323 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,90 +1,87
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QBARSET_H
21 #ifndef QBARSET_H
22 #define QBARSET_H
22 #define QBARSET_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QBrush>
26 #include <QBrush>
27 #include <QFont>
27 #include <QFont>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 class QBarSetPrivate;
30 class QBarSetPrivate;
31
31
32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 Q_PROPERTY(QString name READ name WRITE setName)
35 Q_PROPERTY(QString name READ name WRITE setName)
36
36
37 public:
37 public:
38 explicit QBarSet(const QString name, QObject *parent = 0);
38 explicit QBarSet(const QString name, QObject *parent = 0);
39 virtual ~QBarSet();
39 virtual ~QBarSet();
40
40
41 void setName(const QString name);
41 void setName(const QString name);
42 QString name() const;
42 QString name() const;
43
43
44 void append(const QPointF value);
44 void append(const QPointF value);
45 void append(const QList<QPointF> values);
45 void append(const QList<QPointF> values);
46 void append(const qreal value);
46 void append(const qreal value);
47 void append(const QList<qreal> values);
47 void append(const QList<qreal> values);
48
48
49 QBarSet& operator << (const qreal &value);
49 QBarSet& operator << (const qreal &value);
50 QBarSet& operator << (const QPointF &value);
50 QBarSet& operator << (const QPointF &value);
51
51
52 void insert(const int index, const qreal value);
52 void insert(const int index, const qreal value);
53 void remove(const int index);
53 void remove(const int index);
54 void replace(const int index, const qreal value);
54 void replace(const int index, const qreal value);
55 QPointF at(const int index) const;
55 QPointF at(const int index) const;
56 QPointF operator [] (const int index) const;
56 QPointF operator [] (const int index) const;
57 int count() const;
57 int count() const;
58 qreal sum() const;
58 qreal sum() const;
59
59
60 void setPen(const QPen &pen);
60 void setPen(const QPen &pen);
61 QPen pen() const;
61 QPen pen() const;
62
62
63 void setBrush(const QBrush &brush);
63 void setBrush(const QBrush &brush);
64 QBrush brush() const;
64 QBrush brush() const;
65
65
66 void setLabelPen(const QPen &pen);
67 QPen labelPen() const;
68
69 void setLabelBrush(const QBrush &brush);
66 void setLabelBrush(const QBrush &brush);
70 QBrush labelBrush() const;
67 QBrush labelBrush() const;
71
68
72 void setLabelFont(const QFont &font);
69 void setLabelFont(const QFont &font);
73 QFont labelFont() const;
70 QFont labelFont() const;
74
71
75 //Q_SIGNALS:
72 //Q_SIGNALS:
76 // void clicked(QString category);
73 // void clicked(QString category);
77 // void hovered(bool status);
74 // void hovered(bool status);
78
75
79 private:
76 private:
80 QScopedPointer<QBarSetPrivate> d_ptr;
77 QScopedPointer<QBarSetPrivate> d_ptr;
81 Q_DISABLE_COPY(QBarSet)
78 Q_DISABLE_COPY(QBarSet)
82 friend class QBarSeries;
79 friend class QBarSeries;
83 friend class BarLegendMarker;
80 friend class BarLegendMarker;
84 friend class BarChartItem;
81 friend class BarChartItem;
85 friend class QBarSeriesPrivate;
82 friend class QBarSeriesPrivate;
86 };
83 };
87
84
88 QTCOMMERCIALCHART_END_NAMESPACE
85 QTCOMMERCIALCHART_END_NAMESPACE
89
86
90 #endif // QBARSET_H
87 #endif // QBARSET_H
@@ -1,69 +1,68
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QBARSET_P_H
30 #ifndef QBARSET_P_H
31 #define QBARSET_P_H
31 #define QBARSET_P_H
32
32
33 #include "qbarset.h"
33 #include "qbarset.h"
34 #include <QMap>
34 #include <QMap>
35 #include <QPen>
35 #include <QPen>
36 #include <QBrush>
36 #include <QBrush>
37 #include <QFont>
37 #include <QFont>
38
38
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40
40
41 class QBarSetPrivate : public QObject
41 class QBarSetPrivate : public QObject
42 {
42 {
43 Q_OBJECT
43 Q_OBJECT
44
44
45 public:
45 public:
46 QBarSetPrivate(const QString name, QBarSet *parent);
46 QBarSetPrivate(const QString name, QBarSet *parent);
47 ~QBarSetPrivate();
47 ~QBarSetPrivate();
48
48
49 Q_SIGNALS:
49 Q_SIGNALS:
50 void clicked(QString category);
50 void clicked(QString category);
51 void restructuredBars();
51 void restructuredBars();
52 void updatedBars();
52 void updatedBars();
53
53
54 public:
54 public:
55 QBarSet * const q_ptr;
55 QBarSet * const q_ptr;
56 QString m_name;
56 QString m_name;
57 QList<QPointF> m_values;
57 QList<QPointF> m_values;
58 QPen m_pen;
58 QPen m_pen;
59 QBrush m_brush;
59 QBrush m_brush;
60 QPen m_labelPen;
61 QBrush m_labelBrush;
60 QBrush m_labelBrush;
62 QFont m_labelFont;
61 QFont m_labelFont;
63
62
64 friend class QBarSet;
63 friend class QBarSet;
65 };
64 };
66
65
67 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
68
67
69 #endif // QBARSETPRIVATE_P_H
68 #endif // QBARSETPRIVATE_P_H
@@ -1,385 +1,385
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "charttheme_p.h"
21 #include "charttheme_p.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qchart_p.h"
23 #include "qchart_p.h"
24 #include "qchartview.h"
24 #include "qchartview.h"
25 #include "qlegend.h"
25 #include "qlegend.h"
26 #include "qaxis.h"
26 #include "qaxis.h"
27 #include <QTime>
27 #include <QTime>
28
28
29 //series
29 //series
30 #include "qbarset.h"
30 #include "qbarset.h"
31 #include "qbarseries.h"
31 #include "qbarseries.h"
32 #include "qstackedbarseries.h"
32 #include "qstackedbarseries.h"
33 #include "qpercentbarseries.h"
33 #include "qpercentbarseries.h"
34 #include "qlineseries.h"
34 #include "qlineseries.h"
35 #include "qareaseries.h"
35 #include "qareaseries.h"
36 #include "qscatterseries.h"
36 #include "qscatterseries.h"
37 #include "qpieseries.h"
37 #include "qpieseries.h"
38 #include "qpieslice.h"
38 #include "qpieslice.h"
39 #include "qpieslice_p.h"
39 #include "qpieslice_p.h"
40 #include "qsplineseries.h"
40 #include "qsplineseries.h"
41
41
42 //items
42 //items
43 #include "chartaxis_p.h"
43 #include "chartaxis_p.h"
44 #include "barchartitem_p.h"
44 #include "barchartitem_p.h"
45 #include "stackedbarchartitem_p.h"
45 #include "stackedbarchartitem_p.h"
46 #include "percentbarchartitem_p.h"
46 #include "percentbarchartitem_p.h"
47 #include "linechartitem_p.h"
47 #include "linechartitem_p.h"
48 #include "areachartitem_p.h"
48 #include "areachartitem_p.h"
49 #include "scatterchartitem_p.h"
49 #include "scatterchartitem_p.h"
50 #include "piechartitem_p.h"
50 #include "piechartitem_p.h"
51 #include "splinechartitem_p.h"
51 #include "splinechartitem_p.h"
52
52
53 //themes
53 //themes
54 #include "chartthemesystem_p.h"
54 #include "chartthemesystem_p.h"
55 #include "chartthemelight_p.h"
55 #include "chartthemelight_p.h"
56 #include "chartthemebluecerulean_p.h"
56 #include "chartthemebluecerulean_p.h"
57 #include "chartthemedark_p.h"
57 #include "chartthemedark_p.h"
58 #include "chartthemebrownsand_p.h"
58 #include "chartthemebrownsand_p.h"
59 #include "chartthemebluencs_p.h"
59 #include "chartthemebluencs_p.h"
60 #include "chartthemehighcontrast_p.h"
60 #include "chartthemehighcontrast_p.h"
61 #include "chartthemeblueicy_p.h"
61 #include "chartthemeblueicy_p.h"
62
62
63 QTCOMMERCIALCHART_BEGIN_NAMESPACE
63 QTCOMMERCIALCHART_BEGIN_NAMESPACE
64
64
65 ChartTheme::ChartTheme(QChart::ChartTheme id) :
65 ChartTheme::ChartTheme(QChart::ChartTheme id) :
66 m_masterFont(QFont("arial", 14)),
66 m_masterFont(QFont("arial", 14)),
67 m_labelFont(QFont("arial", 10)),
67 m_labelFont(QFont("arial", 10)),
68 m_titleBrush(QColor(QRgb(0x000000))),
68 m_titleBrush(QColor(QRgb(0x000000))),
69 m_axisLinePen(QPen(QRgb(0x000000))),
69 m_axisLinePen(QPen(QRgb(0x000000))),
70 m_axisLabelBrush(QColor(QRgb(0x000000))),
70 m_axisLabelBrush(QColor(QRgb(0x000000))),
71 m_backgroundShadesPen(Qt::NoPen),
71 m_backgroundShadesPen(Qt::NoPen),
72 m_backgroundShadesBrush(Qt::NoBrush),
72 m_backgroundShadesBrush(Qt::NoBrush),
73 m_backgroundShades(BackgroundShadesNone),
73 m_backgroundShades(BackgroundShadesNone),
74 m_backgroundDropShadowEnabled(false),
74 m_backgroundDropShadowEnabled(false),
75 m_gridLinePen(QPen(QRgb(0x000000))),
75 m_gridLinePen(QPen(QRgb(0x000000))),
76 m_force(false)
76 m_force(false)
77 {
77 {
78 m_id = id;
78 m_id = id;
79 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
79 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
80 }
80 }
81
81
82
82
83 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
83 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
84 {
84 {
85 switch(theme) {
85 switch(theme) {
86 case QChart::ChartThemeLight:
86 case QChart::ChartThemeLight:
87 return new ChartThemeLight();
87 return new ChartThemeLight();
88 case QChart::ChartThemeBlueCerulean:
88 case QChart::ChartThemeBlueCerulean:
89 return new ChartThemeBlueCerulean();
89 return new ChartThemeBlueCerulean();
90 case QChart::ChartThemeDark:
90 case QChart::ChartThemeDark:
91 return new ChartThemeDark();
91 return new ChartThemeDark();
92 case QChart::ChartThemeBrownSand:
92 case QChart::ChartThemeBrownSand:
93 return new ChartThemeBrownSand();
93 return new ChartThemeBrownSand();
94 case QChart::ChartThemeBlueNcs:
94 case QChart::ChartThemeBlueNcs:
95 return new ChartThemeBlueNcs();
95 return new ChartThemeBlueNcs();
96 case QChart::ChartThemeHighContrast:
96 case QChart::ChartThemeHighContrast:
97 return new ChartThemeHighContrast();
97 return new ChartThemeHighContrast();
98 case QChart::ChartThemeBlueIcy:
98 case QChart::ChartThemeBlueIcy:
99 return new ChartThemeBlueIcy();
99 return new ChartThemeBlueIcy();
100 default:
100 default:
101 return new ChartThemeSystem();
101 return new ChartThemeSystem();
102 }
102 }
103 }
103 }
104
104
105 void ChartTheme::decorate(QChart *chart)
105 void ChartTheme::decorate(QChart *chart)
106 {
106 {
107 QBrush brush;
107 QBrush brush;
108
108
109 if(brush == chart->backgroundBrush() || m_force)
109 if(brush == chart->backgroundBrush() || m_force)
110 chart->setBackgroundBrush(m_chartBackgroundGradient);
110 chart->setBackgroundBrush(m_chartBackgroundGradient);
111 chart->setTitleFont(m_masterFont);
111 chart->setTitleFont(m_masterFont);
112 chart->setTitleBrush(m_titleBrush);
112 chart->setTitleBrush(m_titleBrush);
113 chart->setBackgroundDropShadowEnabled(m_backgroundDropShadowEnabled);
113 chart->setBackgroundDropShadowEnabled(m_backgroundDropShadowEnabled);
114 }
114 }
115
115
116 void ChartTheme::decorate(QLegend *legend)
116 void ChartTheme::decorate(QLegend *legend)
117 {
117 {
118 QPen pen;
118 QPen pen;
119 QBrush brush;
119 QBrush brush;
120
120
121 if (pen == legend->pen() || m_force){
121 if (pen == legend->pen() || m_force){
122 legend->setPen(Qt::NoPen);
122 legend->setPen(Qt::NoPen);
123 }
123 }
124
124
125 if (brush == legend->brush() || m_force) {
125 if (brush == legend->brush() || m_force) {
126 legend->setBrush(m_chartBackgroundGradient);
126 legend->setBrush(m_chartBackgroundGradient);
127 }
127 }
128 }
128 }
129
129
130 void ChartTheme::decorate(QAreaSeries *series, int index)
130 void ChartTheme::decorate(QAreaSeries *series, int index)
131 {
131 {
132 QPen pen;
132 QPen pen;
133 QBrush brush;
133 QBrush brush;
134
134
135 if (pen == series->pen() || m_force){
135 if (pen == series->pen() || m_force){
136 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
136 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
137 pen.setWidthF(2);
137 pen.setWidthF(2);
138 series->setPen(pen);
138 series->setPen(pen);
139 }
139 }
140
140
141 if (brush == series->brush() || m_force) {
141 if (brush == series->brush() || m_force) {
142 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
142 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
143 series->setBrush(brush);
143 series->setBrush(brush);
144 }
144 }
145 }
145 }
146
146
147
147
148 void ChartTheme::decorate(QLineSeries *series,int index)
148 void ChartTheme::decorate(QLineSeries *series,int index)
149 {
149 {
150 QPen pen;
150 QPen pen;
151 if(pen == series->pen() || m_force ){
151 if(pen == series->pen() || m_force ){
152 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
152 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
153 pen.setWidthF(2);
153 pen.setWidthF(2);
154 series->setPen(pen);
154 series->setPen(pen);
155 }
155 }
156 }
156 }
157
157
158 void ChartTheme::decorate(QBarSeries *series, int index)
158 void ChartTheme::decorate(QBarSeries *series, int index)
159 {
159 {
160 QBrush brush;
160 QBrush brush;
161 QPen pen;
161 QPen pen;
162 QList<QBarSet *> sets = series->barSets();
162 QList<QBarSet *> sets = series->barSets();
163
163
164 qreal takeAtPos = 0.5;
164 qreal takeAtPos = 0.5;
165 qreal step = 0.2;
165 qreal step = 0.2;
166 if (sets.count() > 1 ) {
166 if (sets.count() > 1 ) {
167 step = 1.0 / (qreal) sets.count();
167 step = 1.0 / (qreal) sets.count();
168 if (sets.count() % m_seriesGradients.count())
168 if (sets.count() % m_seriesGradients.count())
169 step *= m_seriesGradients.count();
169 step *= m_seriesGradients.count();
170 else
170 else
171 step *= (m_seriesGradients.count() - 1);
171 step *= (m_seriesGradients.count() - 1);
172 }
172 }
173
173
174 for (int i(0); i < sets.count(); i++) {
174 for (int i(0); i < sets.count(); i++) {
175 int colorIndex = (index + i) % m_seriesGradients.count();
175 int colorIndex = (index + i) % m_seriesGradients.count();
176 if (i > 0 && i % m_seriesGradients.count() == 0) {
176 if (i > 0 && i % m_seriesGradients.count() == 0) {
177 // There is no dedicated base color for each sets, generate more colors
177 // There is no dedicated base color for each sets, generate more colors
178 takeAtPos += step;
178 takeAtPos += step;
179 if (takeAtPos == 1.0)
179 if (takeAtPos == 1.0)
180 takeAtPos += step;
180 takeAtPos += step;
181 takeAtPos -= (int) takeAtPos;
181 takeAtPos -= (int) takeAtPos;
182 }
182 }
183 if (brush == sets.at(i)->brush() || m_force )
183 if (brush == sets.at(i)->brush() || m_force )
184 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
184 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
185
185
186 // Pick label color from the opposite end of the gradient.
186 // Pick label color from the opposite end of the gradient.
187 // 0.3 as a boundary seems to work well.
187 // 0.3 as a boundary seems to work well.
188 if (takeAtPos < 0.3)
188 if (takeAtPos < 0.3)
189 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
189 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
190 else
190 else
191 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
191 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
192
192
193 if (pen == sets.at(i)->pen() || m_force) {
193 if (pen == sets.at(i)->pen() || m_force) {
194 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
194 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
195 sets.at(i)->setPen(c);
195 sets.at(i)->setPen(c);
196 }
196 }
197 }
197 }
198 }
198 }
199
199
200 void ChartTheme::decorate(QScatterSeries *series, int index)
200 void ChartTheme::decorate(QScatterSeries *series, int index)
201 {
201 {
202 QPen pen;
202 QPen pen;
203 QBrush brush;
203 QBrush brush;
204
204
205 if (pen == series->pen() || m_force) {
205 if (pen == series->pen() || m_force) {
206 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
206 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
207 pen.setWidthF(2);
207 pen.setWidthF(2);
208 series->setPen(pen);
208 series->setPen(pen);
209 }
209 }
210
210
211 if (brush == series->brush() || m_force) {
211 if (brush == series->brush() || m_force) {
212 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
212 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
213 series->setBrush(brush);
213 series->setBrush(brush);
214 }
214 }
215 }
215 }
216
216
217 void ChartTheme::decorate(QPieSeries *series, int index)
217 void ChartTheme::decorate(QPieSeries *series, int index)
218 {
218 {
219
219
220 for (int i(0); i < series->slices().count(); i++) {
220 for (int i(0); i < series->slices().count(); i++) {
221
221
222 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
222 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
223
223
224 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
224 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
225 qreal pos = (qreal) (i + 1) / (qreal) series->count();
225 qreal pos = (qreal) (i + 1) / (qreal) series->count();
226 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
226 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
227
227
228 QPieSlice *s = series->slices().at(i);
228 QPieSlice *s = series->slices().at(i);
229 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
229 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
230
230
231 if (d->m_data.m_slicePen.isThemed() || m_force)
231 if (d->m_data.m_slicePen.isThemed() || m_force)
232 d->setPen(penColor, true);
232 d->setPen(penColor, true);
233
233
234 if (d->m_data.m_sliceBrush.isThemed() || m_force)
234 if (d->m_data.m_sliceBrush.isThemed() || m_force)
235 d->setBrush(brushColor, true);
235 d->setBrush(brushColor, true);
236
236
237 if (d->m_data.m_labelPen.isThemed() || m_force)
237 if (d->m_data.m_labelBrush.isThemed() || m_force)
238 d->setLabelPen(QPen(m_titleBrush.color()), true);
238 d->setLabelBrush(QBrush(m_titleBrush.color()), true);
239
239
240 if (d->m_data.m_labelFont.isThemed() || m_force)
240 if (d->m_data.m_labelFont.isThemed() || m_force)
241 d->setLabelFont(m_labelFont, true);
241 d->setLabelFont(m_labelFont, true);
242 }
242 }
243 }
243 }
244
244
245 void ChartTheme::decorate(QSplineSeries *series, int index)
245 void ChartTheme::decorate(QSplineSeries *series, int index)
246 {
246 {
247 QPen pen;
247 QPen pen;
248 if(pen == series->pen() || m_force){
248 if(pen == series->pen() || m_force){
249 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
249 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
250 pen.setWidthF(2);
250 pen.setWidthF(2);
251 series->setPen(pen);
251 series->setPen(pen);
252 }
252 }
253 }
253 }
254
254
255 void ChartTheme::decorate(QAxis *axis,bool axisX)
255 void ChartTheme::decorate(QAxis *axis,bool axisX)
256 {
256 {
257 QPen pen;
257 QPen pen;
258 QBrush brush;
258 QBrush brush;
259 QFont font;
259 QFont font;
260
260
261 if (axis->isAxisVisible()) {
261 if (axis->isAxisVisible()) {
262
262
263 if(brush == axis->labelsBrush() || m_force){
263 if(brush == axis->labelsBrush() || m_force){
264 axis->setLabelsBrush(m_axisLabelBrush);
264 axis->setLabelsBrush(m_axisLabelBrush);
265 }
265 }
266 if(pen == axis->labelsPen() || m_force){
266 if(pen == axis->labelsPen() || m_force){
267 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
267 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
268 }
268 }
269
269
270
270
271 if (axis->shadesVisible() || m_force) {
271 if (axis->shadesVisible() || m_force) {
272
272
273 if(brush == axis->shadesBrush() || m_force){
273 if(brush == axis->shadesBrush() || m_force){
274 axis->setShadesBrush(m_backgroundShadesBrush);
274 axis->setShadesBrush(m_backgroundShadesBrush);
275 }
275 }
276
276
277 if(pen == axis->shadesPen() || m_force){
277 if(pen == axis->shadesPen() || m_force){
278 axis->setShadesPen(m_backgroundShadesPen);
278 axis->setShadesPen(m_backgroundShadesPen);
279 }
279 }
280
280
281 if( m_force && (m_backgroundShades == BackgroundShadesBoth
281 if( m_force && (m_backgroundShades == BackgroundShadesBoth
282 || (m_backgroundShades == BackgroundShadesVertical && axisX)
282 || (m_backgroundShades == BackgroundShadesVertical && axisX)
283 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
283 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
284 axis->setShadesVisible(true);
284 axis->setShadesVisible(true);
285
285
286 }
286 }
287 }
287 }
288
288
289 if(pen == axis->axisPen() || m_force){
289 if(pen == axis->axisPen() || m_force){
290 axis->setAxisPen(m_axisLinePen);
290 axis->setAxisPen(m_axisLinePen);
291 }
291 }
292
292
293 if(pen == axis->gridLinePen() || m_force){
293 if(pen == axis->gridLinePen() || m_force){
294 axis->setGridLinePen(m_gridLinePen);
294 axis->setGridLinePen(m_gridLinePen);
295 }
295 }
296
296
297 if(font == axis->labelsFont() || m_force){
297 if(font == axis->labelsFont() || m_force){
298 axis->setLabelsFont(m_labelFont);
298 axis->setLabelsFont(m_labelFont);
299 }
299 }
300 }
300 }
301 }
301 }
302
302
303 void ChartTheme::generateSeriesGradients()
303 void ChartTheme::generateSeriesGradients()
304 {
304 {
305 // Generate gradients in HSV color space
305 // Generate gradients in HSV color space
306 foreach (const QColor& color, m_seriesColors) {
306 foreach (const QColor& color, m_seriesColors) {
307 QLinearGradient g;
307 QLinearGradient g;
308 qreal h = color.hsvHueF();
308 qreal h = color.hsvHueF();
309 qreal s = color.hsvSaturationF();
309 qreal s = color.hsvSaturationF();
310
310
311 // TODO: tune the algorithm to give nice results with most base colors defined in
311 // TODO: tune the algorithm to give nice results with most base colors defined in
312 // most themes. The rest of the gradients we can define manually in theme specific
312 // most themes. The rest of the gradients we can define manually in theme specific
313 // implementation.
313 // implementation.
314 QColor start = color;
314 QColor start = color;
315 start.setHsvF(h, 0.0, 1.0);
315 start.setHsvF(h, 0.0, 1.0);
316 g.setColorAt(0.0, start);
316 g.setColorAt(0.0, start);
317
317
318 g.setColorAt(0.5, color);
318 g.setColorAt(0.5, color);
319
319
320 QColor end = color;
320 QColor end = color;
321 end.setHsvF(h, s, 0.25);
321 end.setHsvF(h, s, 0.25);
322 g.setColorAt(1.0, end);
322 g.setColorAt(1.0, end);
323
323
324 m_seriesGradients << g;
324 m_seriesGradients << g;
325 }
325 }
326 }
326 }
327
327
328
328
329 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
329 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
330 {
330 {
331 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
331 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
332 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
332 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
333 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
333 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
334 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
334 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
335 QColor c;
335 QColor c;
336 c.setRgbF(r, g, b);
336 c.setRgbF(r, g, b);
337 return c;
337 return c;
338 }
338 }
339
339
340 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
340 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
341 {
341 {
342 Q_ASSERT(pos >= 0 && pos <= 1.0);
342 Q_ASSERT(pos >= 0 && pos <= 1.0);
343
343
344 QGradientStops stops = gradient.stops();
344 QGradientStops stops = gradient.stops();
345 int count = stops.count();
345 int count = stops.count();
346
346
347 // find previous stop relative to position
347 // find previous stop relative to position
348 QGradientStop prev = stops.first();
348 QGradientStop prev = stops.first();
349 for (int i = 0; i < count; i++) {
349 for (int i = 0; i < count; i++) {
350 QGradientStop stop = stops.at(i);
350 QGradientStop stop = stops.at(i);
351 if (pos > stop.first)
351 if (pos > stop.first)
352 prev = stop;
352 prev = stop;
353
353
354 // given position is actually a stop position?
354 // given position is actually a stop position?
355 if (pos == stop.first) {
355 if (pos == stop.first) {
356 //qDebug() << "stop color" << pos;
356 //qDebug() << "stop color" << pos;
357 return stop.second;
357 return stop.second;
358 }
358 }
359 }
359 }
360
360
361 // find next stop relative to position
361 // find next stop relative to position
362 QGradientStop next = stops.last();
362 QGradientStop next = stops.last();
363 for (int i = count - 1; i >= 0; i--) {
363 for (int i = count - 1; i >= 0; i--) {
364 QGradientStop stop = stops.at(i);
364 QGradientStop stop = stops.at(i);
365 if (pos < stop.first)
365 if (pos < stop.first)
366 next = stop;
366 next = stop;
367 }
367 }
368
368
369 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
369 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
370
370
371 qreal range = next.first - prev.first;
371 qreal range = next.first - prev.first;
372 qreal posDelta = pos - prev.first;
372 qreal posDelta = pos - prev.first;
373 qreal relativePos = posDelta / range;
373 qreal relativePos = posDelta / range;
374
374
375 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
375 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
376
376
377 return colorAt(prev.second, next.second, relativePos);
377 return colorAt(prev.second, next.second, relativePos);
378 }
378 }
379
379
380 void ChartTheme::setForced(bool enabled)
380 void ChartTheme::setForced(bool enabled)
381 {
381 {
382 m_force=enabled;
382 m_force=enabled;
383 }
383 }
384
384
385 QTCOMMERCIALCHART_END_NAMESPACE
385 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,208 +1,208
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "piechartitem_p.h"
21 #include "piechartitem_p.h"
22 #include "piesliceitem_p.h"
22 #include "piesliceitem_p.h"
23 #include "qpieslice.h"
23 #include "qpieslice.h"
24 #include "qpieslice_p.h"
24 #include "qpieslice_p.h"
25 #include "qpieseries.h"
25 #include "qpieseries.h"
26 #include "qpieseries_p.h"
26 #include "qpieseries_p.h"
27 #include "chartpresenter_p.h"
27 #include "chartpresenter_p.h"
28 #include "chartdataset_p.h"
28 #include "chartdataset_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30 #include <QPainter>
30 #include <QPainter>
31 #include <QTimer>
31 #include <QTimer>
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter)
35 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter)
36 :ChartItem(presenter),
36 :ChartItem(presenter),
37 m_series(series)
37 m_series(series)
38 {
38 {
39 Q_ASSERT(series);
39 Q_ASSERT(series);
40
40
41 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
41 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
42 connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
42 connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
43 connect(series, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout()));
43 connect(series, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout()));
44 connect(series, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout()));
44 connect(series, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout()));
45 connect(series, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout()));
45 connect(series, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout()));
46 connect(QPieSeriesPrivate::fromSeries(series), SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout()));
46 connect(QPieSeriesPrivate::fromSeries(series), SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout()));
47
47
48 // Note: the following does not affect as long as the item does not have anything to paint
48 // Note: the following does not affect as long as the item does not have anything to paint
49 setZValue(ChartPresenter::PieSeriesZValue);
49 setZValue(ChartPresenter::PieSeriesZValue);
50
50
51 // Note: will not create slice items until we have a proper rectangle to draw on.
51 // Note: will not create slice items until we have a proper rectangle to draw on.
52 }
52 }
53
53
54 PieChartItem::~PieChartItem()
54 PieChartItem::~PieChartItem()
55 {
55 {
56 // slices deleted automatically through QGraphicsItem
56 // slices deleted automatically through QGraphicsItem
57 }
57 }
58
58
59 void PieChartItem::handleGeometryChanged(const QRectF& rect)
59 void PieChartItem::handleGeometryChanged(const QRectF& rect)
60 {
60 {
61 prepareGeometryChange();
61 prepareGeometryChange();
62 m_rect = rect;
62 m_rect = rect;
63 updateLayout();
63 updateLayout();
64
64
65 // This is for delayed initialization of the slice items during startup.
65 // This is for delayed initialization of the slice items during startup.
66 // It ensures that startup animation originates from the correct position.
66 // It ensures that startup animation originates from the correct position.
67 if (m_sliceItems.isEmpty())
67 if (m_sliceItems.isEmpty())
68 handleSlicesAdded(m_series->slices());
68 handleSlicesAdded(m_series->slices());
69 }
69 }
70
70
71 void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
71 void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
72 {
72 {
73 Q_UNUSED(minX);
73 Q_UNUSED(minX);
74 Q_UNUSED(maxX);
74 Q_UNUSED(maxX);
75 Q_UNUSED(minY);
75 Q_UNUSED(minY);
76 Q_UNUSED(maxY);
76 Q_UNUSED(maxY);
77 // does not apply to pie
77 // does not apply to pie
78 }
78 }
79
79
80 void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount)
80 void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount)
81 {
81 {
82 Q_UNUSED(min);
82 Q_UNUSED(min);
83 Q_UNUSED(max);
83 Q_UNUSED(max);
84 Q_UNUSED(tickXCount);
84 Q_UNUSED(tickXCount);
85 // does not apply to pie
85 // does not apply to pie
86 }
86 }
87
87
88 void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount)
88 void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount)
89 {
89 {
90 Q_UNUSED(min);
90 Q_UNUSED(min);
91 Q_UNUSED(max);
91 Q_UNUSED(max);
92 Q_UNUSED(tickYCount);
92 Q_UNUSED(tickYCount);
93 // does not apply to pie
93 // does not apply to pie
94 }
94 }
95
95
96 void PieChartItem::updateLayout()
96 void PieChartItem::updateLayout()
97 {
97 {
98 // find pie center coordinates
98 // find pie center coordinates
99 m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->horizontalPosition()));
99 m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->horizontalPosition()));
100 m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->verticalPosition()));
100 m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->verticalPosition()));
101
101
102 // find maximum radius for pie
102 // find maximum radius for pie
103 m_pieRadius = m_rect.height() / 2;
103 m_pieRadius = m_rect.height() / 2;
104 if (m_rect.width() < m_rect.height())
104 if (m_rect.width() < m_rect.height())
105 m_pieRadius = m_rect.width() / 2;
105 m_pieRadius = m_rect.width() / 2;
106
106
107 // apply size factor
107 // apply size factor
108 m_pieRadius *= m_series->pieSize();
108 m_pieRadius *= m_series->pieSize();
109
109
110 // set layouts for existing slice items
110 // set layouts for existing slice items
111 foreach (QPieSlice* slice, m_series->slices()) {
111 foreach (QPieSlice* slice, m_series->slices()) {
112 PieSliceItem *sliceItem = m_sliceItems.value(slice);
112 PieSliceItem *sliceItem = m_sliceItems.value(slice);
113 if (sliceItem) {
113 if (sliceItem) {
114 PieSliceData sliceData = updateSliceGeometry(slice);
114 PieSliceData sliceData = updateSliceGeometry(slice);
115 if (animator())
115 if (animator())
116 animator()->updateAnimation(this, sliceItem, sliceData);
116 animator()->updateAnimation(this, sliceItem, sliceData);
117 else
117 else
118 sliceItem->setLayout(sliceData);
118 sliceItem->setLayout(sliceData);
119 }
119 }
120 }
120 }
121
121
122 update();
122 update();
123 }
123 }
124
124
125 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
125 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
126 {
126 {
127 // delay creating slice items until there is a proper rectangle
127 // delay creating slice items until there is a proper rectangle
128 if (!m_rect.isValid() && m_sliceItems.isEmpty())
128 if (!m_rect.isValid() && m_sliceItems.isEmpty())
129 return;
129 return;
130
130
131 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
131 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
132
132
133 bool startupAnimation = m_sliceItems.isEmpty();
133 bool startupAnimation = m_sliceItems.isEmpty();
134
134
135 foreach (QPieSlice *slice, slices) {
135 foreach (QPieSlice *slice, slices) {
136 PieSliceItem* sliceItem = new PieSliceItem(this);
136 PieSliceItem* sliceItem = new PieSliceItem(this);
137 m_sliceItems.insert(slice, sliceItem);
137 m_sliceItems.insert(slice, sliceItem);
138
138
139 // Note: do need to connect to slice valueChanged() etc.
139 // Note: do need to connect to slice valueChanged() etc.
140 // This is handled through calculatedDataChanged signal.
140 // This is handled through calculatedDataChanged signal.
141 connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged()));
141 connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged()));
142 connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged()));
142 connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged()));
143 connect(slice, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged()));
143 connect(slice, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged()));
144 connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged()));
144 connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged()));
145 connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged()));
145 connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged()));
146 connect(slice, SIGNAL(labelPenChanged()), this, SLOT(handleSliceChanged()));
146 connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged()));
147 connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged()));
147 connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged()));
148 connect(slice, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged()));
148 connect(slice, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged()));
149 connect(slice, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged()));
149 connect(slice, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged()));
150
150
151 connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked()));
151 connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked()));
152 connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool)));
152 connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool)));
153
153
154 PieSliceData sliceData = updateSliceGeometry(slice);
154 PieSliceData sliceData = updateSliceGeometry(slice);
155 if (animator())
155 if (animator())
156 animator()->addAnimation(this, sliceItem, sliceData, startupAnimation);
156 animator()->addAnimation(this, sliceItem, sliceData, startupAnimation);
157 else
157 else
158 sliceItem->setLayout(sliceData);
158 sliceItem->setLayout(sliceData);
159 }
159 }
160 }
160 }
161
161
162 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
162 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
163 {
163 {
164 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
164 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
165
165
166 foreach (QPieSlice *slice, slices) {
166 foreach (QPieSlice *slice, slices) {
167
167
168 PieSliceItem *sliceItem = m_sliceItems.value(slice);
168 PieSliceItem *sliceItem = m_sliceItems.value(slice);
169
169
170 // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created
170 // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created
171 if (!sliceItem)
171 if (!sliceItem)
172 continue;
172 continue;
173
173
174 m_sliceItems.remove(slice);
174 m_sliceItems.remove(slice);
175
175
176 if (animator())
176 if (animator())
177 animator()->removeAnimation(this, sliceItem); // animator deletes the PieSliceItem
177 animator()->removeAnimation(this, sliceItem); // animator deletes the PieSliceItem
178 else
178 else
179 delete sliceItem;
179 delete sliceItem;
180 }
180 }
181 }
181 }
182
182
183 void PieChartItem::handleSliceChanged()
183 void PieChartItem::handleSliceChanged()
184 {
184 {
185 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
185 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
186 Q_ASSERT(m_sliceItems.contains(slice));
186 Q_ASSERT(m_sliceItems.contains(slice));
187
187
188 PieSliceItem *sliceItem = m_sliceItems.value(slice);
188 PieSliceItem *sliceItem = m_sliceItems.value(slice);
189 PieSliceData sliceData = updateSliceGeometry(slice);
189 PieSliceData sliceData = updateSliceGeometry(slice);
190 if (animator())
190 if (animator())
191 animator()->updateAnimation(this, sliceItem, sliceData);
191 animator()->updateAnimation(this, sliceItem, sliceData);
192 else
192 else
193 sliceItem->setLayout(sliceData);
193 sliceItem->setLayout(sliceData);
194
194
195 update();
195 update();
196 }
196 }
197
197
198 PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice)
198 PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice)
199 {
199 {
200 PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data;
200 PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data;
201 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
201 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
202 sliceData.m_radius = m_pieRadius;
202 sliceData.m_radius = m_pieRadius;
203 return sliceData;
203 return sliceData;
204 }
204 }
205
205
206 #include "moc_piechartitem_p.cpp"
206 #include "moc_piechartitem_p.cpp"
207
207
208 QTCOMMERCIALCHART_END_NAMESPACE
208 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,130 +1,130
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef PIESLICEDATA_P_H
21 #ifndef PIESLICEDATA_P_H
22 #define PIESLICEDATA_P_H
22 #define PIESLICEDATA_P_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qpieslice.h"
25 #include "qpieslice.h"
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 template <class T>
31 template <class T>
32 class Themed : public T
32 class Themed : public T
33 {
33 {
34 public:
34 public:
35 Themed():m_isThemed(true) {}
35 Themed():m_isThemed(true) {}
36
36
37 inline T &operator=(const T &other) { return T::operator =(other); }
37 inline T &operator=(const T &other) { return T::operator =(other); }
38
38
39 inline bool operator!=(const T &other) const { return T::operator !=(other); }
39 inline bool operator!=(const T &other) const { return T::operator !=(other); }
40 inline bool operator!=(const Themed &other) const
40 inline bool operator!=(const Themed &other) const
41 {
41 {
42 if (T::operator !=(other))
42 if (T::operator !=(other))
43 return true;
43 return true;
44
44
45 if (m_isThemed != other.m_isThemed)
45 if (m_isThemed != other.m_isThemed)
46 return true;
46 return true;
47
47
48 return false;
48 return false;
49 }
49 }
50
50
51 inline void setThemed(bool state) { m_isThemed = state; }
51 inline void setThemed(bool state) { m_isThemed = state; }
52 inline bool isThemed() const { return m_isThemed; }
52 inline bool isThemed() const { return m_isThemed; }
53
53
54 private:
54 private:
55 bool m_isThemed;
55 bool m_isThemed;
56 };
56 };
57
57
58 class PieSliceData
58 class PieSliceData
59 {
59 {
60 public:
60 public:
61 PieSliceData()
61 PieSliceData()
62 {
62 {
63 m_value = 0;
63 m_value = 0;
64
64
65 m_isExploded = false;
65 m_isExploded = false;
66 m_explodeDistanceFactor = 0.15;
66 m_explodeDistanceFactor = 0.15;
67
67
68 m_isLabelVisible = false;
68 m_isLabelVisible = false;
69 m_labelArmLengthFactor = 0.15;
69 m_labelArmLengthFactor = 0.15;
70
70
71 m_percentage = 0;
71 m_percentage = 0;
72 m_radius = 0;
72 m_radius = 0;
73 m_startAngle = 0;
73 m_startAngle = 0;
74 m_angleSpan = 0;
74 m_angleSpan = 0;
75 }
75 }
76
76
77 bool operator!=(const PieSliceData &other) const
77 bool operator!=(const PieSliceData &other) const
78 {
78 {
79 if (!qFuzzyIsNull(m_value - other.m_value))
79 if (!qFuzzyIsNull(m_value - other.m_value))
80 return true;
80 return true;
81
81
82 if (m_slicePen != other.m_slicePen ||
82 if (m_slicePen != other.m_slicePen ||
83 m_sliceBrush != other.m_sliceBrush)
83 m_sliceBrush != other.m_sliceBrush)
84 return true;
84 return true;
85
85
86 if (m_isExploded != other.m_isExploded ||
86 if (m_isExploded != other.m_isExploded ||
87 !qFuzzyIsNull(m_explodeDistanceFactor - other.m_explodeDistanceFactor))
87 !qFuzzyIsNull(m_explodeDistanceFactor - other.m_explodeDistanceFactor))
88 return true;
88 return true;
89
89
90 if (m_isLabelVisible != other.m_isLabelVisible ||
90 if (m_isLabelVisible != other.m_isLabelVisible ||
91 m_labelText != other.m_labelText ||
91 m_labelText != other.m_labelText ||
92 m_labelFont != other.m_labelFont ||
92 m_labelFont != other.m_labelFont ||
93 !qFuzzyIsNull(m_labelArmLengthFactor - other.m_labelArmLengthFactor) ||
93 !qFuzzyIsNull(m_labelArmLengthFactor - other.m_labelArmLengthFactor) ||
94 m_labelPen != other.m_labelPen)
94 m_labelBrush != other.m_labelBrush)
95 return true;
95 return true;
96
96
97 if (!qFuzzyIsNull(m_percentage - other.m_percentage) ||
97 if (!qFuzzyIsNull(m_percentage - other.m_percentage) ||
98 m_center != other.m_center ||
98 m_center != other.m_center ||
99 !qFuzzyIsNull(m_radius - other.m_radius) ||
99 !qFuzzyIsNull(m_radius - other.m_radius) ||
100 !qFuzzyIsNull(m_startAngle - other.m_startAngle) ||
100 !qFuzzyIsNull(m_startAngle - other.m_startAngle) ||
101 !qFuzzyIsNull(m_angleSpan - other.m_angleSpan))
101 !qFuzzyIsNull(m_angleSpan - other.m_angleSpan))
102 return true;
102 return true;
103
103
104 return false;
104 return false;
105 }
105 }
106
106
107 qreal m_value;
107 qreal m_value;
108
108
109 Themed<QPen> m_slicePen;
109 Themed<QPen> m_slicePen;
110 Themed<QBrush> m_sliceBrush;
110 Themed<QBrush> m_sliceBrush;
111
111
112 bool m_isExploded;
112 bool m_isExploded;
113 qreal m_explodeDistanceFactor;
113 qreal m_explodeDistanceFactor;
114
114
115 bool m_isLabelVisible;
115 bool m_isLabelVisible;
116 QString m_labelText;
116 QString m_labelText;
117 Themed<QFont> m_labelFont;
117 Themed<QFont> m_labelFont;
118 qreal m_labelArmLengthFactor;
118 qreal m_labelArmLengthFactor;
119 Themed<QPen> m_labelPen;
119 Themed<QBrush> m_labelBrush;
120
120
121 qreal m_percentage;
121 qreal m_percentage;
122 QPointF m_center;
122 QPointF m_center;
123 qreal m_radius;
123 qreal m_radius;
124 qreal m_startAngle;
124 qreal m_startAngle;
125 qreal m_angleSpan;
125 qreal m_angleSpan;
126 };
126 };
127
127
128 QTCOMMERCIALCHART_END_NAMESPACE
128 QTCOMMERCIALCHART_END_NAMESPACE
129
129
130 #endif // PIESLICEDATA_P_H
130 #endif // PIESLICEDATA_P_H
@@ -1,223 +1,224
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "piesliceitem_p.h"
21 #include "piesliceitem_p.h"
22 #include "piechartitem_p.h"
22 #include "piechartitem_p.h"
23 #include "qpieseries.h"
23 #include "qpieseries.h"
24 #include "qpieslice.h"
24 #include "qpieslice.h"
25 #include "chartpresenter_p.h"
25 #include "chartpresenter_p.h"
26 #include <QPainter>
26 #include <QPainter>
27 #include <qmath.h>
27 #include <qmath.h>
28 #include <QGraphicsSceneEvent>
28 #include <QGraphicsSceneEvent>
29 #include <QTime>
29 #include <QTime>
30 #include <QDebug>
30 #include <QDebug>
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 #define PI 3.14159265 // TODO: is this defined in some header?
34 #define PI 3.14159265 // TODO: is this defined in some header?
35
35
36 QPointF offset(qreal angle, qreal length)
36 QPointF offset(qreal angle, qreal length)
37 {
37 {
38 qreal dx = qSin(angle*(PI/180)) * length;
38 qreal dx = qSin(angle*(PI/180)) * length;
39 qreal dy = qCos(angle*(PI/180)) * length;
39 qreal dy = qCos(angle*(PI/180)) * length;
40 return QPointF(dx, -dy);
40 return QPointF(dx, -dy);
41 }
41 }
42
42
43 PieSliceItem::PieSliceItem(QGraphicsItem* parent)
43 PieSliceItem::PieSliceItem(QGraphicsItem* parent)
44 :QGraphicsObject(parent),
44 :QGraphicsObject(parent),
45 m_hovered(false)
45 m_hovered(false)
46 {
46 {
47 setAcceptHoverEvents(true);
47 setAcceptHoverEvents(true);
48 setAcceptedMouseButtons(Qt::MouseButtonMask);
48 setAcceptedMouseButtons(Qt::MouseButtonMask);
49 setZValue(ChartPresenter::PieSeriesZValue);
49 setZValue(ChartPresenter::PieSeriesZValue);
50 }
50 }
51
51
52 PieSliceItem::~PieSliceItem()
52 PieSliceItem::~PieSliceItem()
53 {
53 {
54 // If user is hovering over the slice and it gets destroyed we do
54 // If user is hovering over the slice and it gets destroyed we do
55 // not get a hover leave event. So we must emit the signal here.
55 // not get a hover leave event. So we must emit the signal here.
56 if (m_hovered)
56 if (m_hovered)
57 emit hovered(false);
57 emit hovered(false);
58 }
58 }
59
59
60 QRectF PieSliceItem::boundingRect() const
60 QRectF PieSliceItem::boundingRect() const
61 {
61 {
62 return m_boundingRect;
62 return m_boundingRect;
63 }
63 }
64
64
65 QPainterPath PieSliceItem::shape() const
65 QPainterPath PieSliceItem::shape() const
66 {
66 {
67 // Don't include the label and label arm.
67 // Don't include the label and label arm.
68 // This is used to detect a mouse clicks. We do not want clicks from label.
68 // This is used to detect a mouse clicks. We do not want clicks from label.
69 return m_slicePath;
69 return m_slicePath;
70 }
70 }
71
71
72 void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
72 void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
73 {
73 {
74 painter->save();
74 painter->save();
75 painter->setClipRect(parentItem()->boundingRect());
75 painter->setClipRect(parentItem()->boundingRect());
76 painter->setPen(m_data.m_slicePen);
76 painter->setPen(m_data.m_slicePen);
77 painter->setBrush(m_data.m_sliceBrush);
77 painter->setBrush(m_data.m_sliceBrush);
78 painter->drawPath(m_slicePath);
78 painter->drawPath(m_slicePath);
79 painter->restore();
79 painter->restore();
80
80
81 if (m_data.m_isLabelVisible) {
81 if (m_data.m_isLabelVisible) {
82 painter->save();
82 painter->save();
83 painter->setClipRect(parentItem()->boundingRect());
83 painter->setClipRect(parentItem()->boundingRect());
84 painter->setPen(m_data.m_labelPen);
84 // Pen for label arm not defined in the QPieSeries api, let's use brush's color instead
85 // Also, the drawText actually uses the pen color for the text color (unlike QGraphicsSimpleTextItem)
86 painter->setPen(m_data.m_labelBrush.color());
85 painter->drawPath(m_labelArmPath);
87 painter->drawPath(m_labelArmPath);
86 // the pen color will affect the font color as well
87 painter->setFont(m_data.m_labelFont);
88 painter->setFont(m_data.m_labelFont);
88 painter->drawText(m_labelTextRect.bottomLeft(), m_data.m_labelText);
89 painter->drawText(m_labelTextRect.bottomLeft(), m_data.m_labelText);
89 painter->restore();
90 painter->restore();
90 }
91 }
91 }
92 }
92
93
93 void PieSliceItem::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/)
94 void PieSliceItem::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/)
94 {
95 {
95 m_hovered = true;
96 m_hovered = true;
96 emit hovered(true);
97 emit hovered(true);
97 }
98 }
98
99
99 void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
100 void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
100 {
101 {
101 m_hovered = false;
102 m_hovered = false;
102 emit hovered(false);
103 emit hovered(false);
103 }
104 }
104
105
105 void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
106 void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
106 {
107 {
107 emit clicked(event->buttons());
108 emit clicked(event->buttons());
108 }
109 }
109
110
110 void PieSliceItem::setLayout(const PieSliceData &sliceData)
111 void PieSliceItem::setLayout(const PieSliceData &sliceData)
111 {
112 {
112 m_data = sliceData;
113 m_data = sliceData;
113 updateGeometry();
114 updateGeometry();
114 update();
115 update();
115 }
116 }
116
117
117 void PieSliceItem::updateGeometry()
118 void PieSliceItem::updateGeometry()
118 {
119 {
119 if (m_data.m_radius <= 0)
120 if (m_data.m_radius <= 0)
120 return;
121 return;
121
122
122 prepareGeometryChange();
123 prepareGeometryChange();
123
124
124 // update slice path
125 // update slice path
125 qreal centerAngle;
126 qreal centerAngle;
126 QPointF armStart;
127 QPointF armStart;
127 m_slicePath = slicePath(m_data.m_center, m_data.m_radius, m_data.m_startAngle, m_data.m_angleSpan, &centerAngle, &armStart);
128 m_slicePath = slicePath(m_data.m_center, m_data.m_radius, m_data.m_startAngle, m_data.m_angleSpan, &centerAngle, &armStart);
128
129
129 // update text rect
130 // update text rect
130 m_labelTextRect = labelTextRect(m_data.m_labelFont, m_data.m_labelText);
131 m_labelTextRect = labelTextRect(m_data.m_labelFont, m_data.m_labelText);
131
132
132 // update label arm path
133 // update label arm path
133 QPointF labelTextStart;
134 QPointF labelTextStart;
134 m_labelArmPath = labelArmPath(armStart, centerAngle, m_data.m_radius * m_data.m_labelArmLengthFactor, m_labelTextRect.width(), &labelTextStart);
135 m_labelArmPath = labelArmPath(armStart, centerAngle, m_data.m_radius * m_data.m_labelArmLengthFactor, m_labelTextRect.width(), &labelTextStart);
135
136
136 // update text position
137 // update text position
137 m_labelTextRect.moveBottomLeft(labelTextStart);
138 m_labelTextRect.moveBottomLeft(labelTextStart);
138
139
139 // update bounding rect
140 // update bounding rect
140 if (m_data.m_isLabelVisible)
141 if (m_data.m_isLabelVisible)
141 m_boundingRect = m_slicePath.boundingRect().united(m_labelArmPath.boundingRect()).united(m_labelTextRect);
142 m_boundingRect = m_slicePath.boundingRect().united(m_labelArmPath.boundingRect()).united(m_labelTextRect);
142 else
143 else
143 m_boundingRect = m_slicePath.boundingRect();
144 m_boundingRect = m_slicePath.boundingRect();
144 }
145 }
145
146
146 QPointF PieSliceItem::sliceCenter(QPointF point, qreal radius, QPieSlice *slice)
147 QPointF PieSliceItem::sliceCenter(QPointF point, qreal radius, QPieSlice *slice)
147 {
148 {
148 if (slice->isExploded()) {
149 if (slice->isExploded()) {
149 qreal centerAngle = slice->startAngle() + (slice->angleSpan()/2);
150 qreal centerAngle = slice->startAngle() + (slice->angleSpan()/2);
150 qreal len = radius * slice->explodeDistanceFactor();
151 qreal len = radius * slice->explodeDistanceFactor();
151 qreal dx = qSin(centerAngle*(PI/180)) * len;
152 qreal dx = qSin(centerAngle*(PI/180)) * len;
152 qreal dy = -qCos(centerAngle*(PI/180)) * len;
153 qreal dy = -qCos(centerAngle*(PI/180)) * len;
153 point += QPointF(dx, dy);
154 point += QPointF(dx, dy);
154 }
155 }
155 return point;
156 return point;
156 }
157 }
157
158
158 QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal *centerAngle, QPointF* armStart)
159 QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal *centerAngle, QPointF* armStart)
159 {
160 {
160 // calculate center angle
161 // calculate center angle
161 *centerAngle = startAngle + (angleSpan/2);
162 *centerAngle = startAngle + (angleSpan/2);
162
163
163 // calculate slice rectangle
164 // calculate slice rectangle
164 QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2);
165 QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2);
165
166
166 // slice path
167 // slice path
167 // TODO: draw the shape so that it might have a hole in the center
168 // TODO: draw the shape so that it might have a hole in the center
168 QPainterPath path;
169 QPainterPath path;
169 path.moveTo(rect.center());
170 path.moveTo(rect.center());
170 path.arcTo(rect, -startAngle + 90, -angleSpan);
171 path.arcTo(rect, -startAngle + 90, -angleSpan);
171 path.closeSubpath();
172 path.closeSubpath();
172
173
173 // calculate label arm start point
174 // calculate label arm start point
174 *armStart = center;
175 *armStart = center;
175 *armStart += offset(*centerAngle, radius + PIESLICE_LABEL_GAP);
176 *armStart += offset(*centerAngle, radius + PIESLICE_LABEL_GAP);
176
177
177 return path;
178 return path;
178 }
179 }
179
180
180 QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF *textStart)
181 QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF *textStart)
181 {
182 {
182 // prevent label arm pointing straight down because it will look bad
183 // prevent label arm pointing straight down because it will look bad
183 if (angle < 180 && angle > 170)
184 if (angle < 180 && angle > 170)
184 angle = 170;
185 angle = 170;
185 if (angle > 180 && angle < 190)
186 if (angle > 180 && angle < 190)
186 angle = 190;
187 angle = 190;
187
188
188 // line from slice to label
189 // line from slice to label
189 qreal dx = qSin(angle*(PI/180)) * length;
190 qreal dx = qSin(angle*(PI/180)) * length;
190 qreal dy = -qCos(angle*(PI/180)) * length;
191 qreal dy = -qCos(angle*(PI/180)) * length;
191 QPointF parm1 = start + QPointF(dx, dy);
192 QPointF parm1 = start + QPointF(dx, dy);
192
193
193 // line to underline the label
194 // line to underline the label
194 QPointF parm2 = parm1;
195 QPointF parm2 = parm1;
195 if (angle < 180) { // arm swings the other way on the left side
196 if (angle < 180) { // arm swings the other way on the left side
196 parm2 += QPointF(textWidth, 0);
197 parm2 += QPointF(textWidth, 0);
197 *textStart = parm1;
198 *textStart = parm1;
198 }
199 }
199 else {
200 else {
200 parm2 += QPointF(-textWidth,0);
201 parm2 += QPointF(-textWidth,0);
201 *textStart = parm2;
202 *textStart = parm2;
202 }
203 }
203
204
204 // elevate the text position a bit so that it does not hit the line
205 // elevate the text position a bit so that it does not hit the line
205 *textStart += QPointF(0, -3);
206 *textStart += QPointF(0, -3);
206
207
207 QPainterPath path;
208 QPainterPath path;
208 path.moveTo(start);
209 path.moveTo(start);
209 path.lineTo(parm1);
210 path.lineTo(parm1);
210 path.lineTo(parm2);
211 path.lineTo(parm2);
211
212
212 return path;
213 return path;
213 }
214 }
214
215
215 QRectF PieSliceItem::labelTextRect(QFont font, QString text)
216 QRectF PieSliceItem::labelTextRect(QFont font, QString text)
216 {
217 {
217 QFontMetricsF fm(font);
218 QFontMetricsF fm(font);
218 return fm.boundingRect(text);
219 return fm.boundingRect(text);
219 }
220 }
220
221
221 #include "moc_piesliceitem_p.cpp"
222 #include "moc_piesliceitem_p.cpp"
222
223
223 QTCOMMERCIALCHART_END_NAMESPACE
224 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,536 +1,536
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qpieslice.h"
21 #include "qpieslice.h"
22 #include "qpieslice_p.h"
22 #include "qpieslice_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QPieSlice
27 \class QPieSlice
28 \brief Defines a slice in pie series.
28 \brief Defines a slice in pie series.
29
29
30 This object defines the properties of a single slice in a QPieSeries.
30 This object defines the properties of a single slice in a QPieSeries.
31
31
32 In addition to the obvious value and label properties the user can also control
32 In addition to the obvious value and label properties the user can also control
33 the visual appearance of a slice. By modifying the visual appearance also means that
33 the visual appearance of a slice. By modifying the visual appearance also means that
34 the user is overriding the default appearance set by the theme.
34 the user is overriding the default appearance set by the theme.
35
35
36 Note that if the user has customized slices and theme is changed all customizations will be lost.
36 Note that if the user has customized slices and theme is changed all customizations will be lost.
37
37
38 To enable user interaction with the pie some basic signals are provided about clicking and hovering.
38 To enable user interaction with the pie some basic signals are provided about clicking and hovering.
39 */
39 */
40
40
41 /*!
41 /*!
42 \property QPieSlice::label
42 \property QPieSlice::label
43
43
44 Label of the slice.
44 Label of the slice.
45
45
46 \sa labelVisible, labelPen, labelFont, labelArmLengthFactor
46 \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor
47 */
47 */
48
48
49 /*!
49 /*!
50 \fn void QPieSlice::labelChanged()
50 \fn void QPieSlice::labelChanged()
51
51
52 This signal emitted when the slice label has been changed.
52 This signal emitted when the slice label has been changed.
53
53
54 \sa label
54 \sa label
55 */
55 */
56
56
57 /*!
57 /*!
58 \property QPieSlice::value
58 \property QPieSlice::value
59
59
60 Value of the slice.
60 Value of the slice.
61
61
62 Note that if users sets a negative value it is converted to a positive value.
62 Note that if users sets a negative value it is converted to a positive value.
63
63
64 \sa percentage(), QPieSeries::sum()
64 \sa percentage(), QPieSeries::sum()
65 */
65 */
66
66
67 /*!
67 /*!
68 \fn void QPieSlice::valueChanged()
68 \fn void QPieSlice::valueChanged()
69
69
70 This signal is emitted when the slice value changes.
70 This signal is emitted when the slice value changes.
71
71
72 \sa value
72 \sa value
73 */
73 */
74
74
75 /*!
75 /*!
76 \property QPieSlice::labelVisible
76 \property QPieSlice::labelVisible
77
77
78 Defienes the visibility of the slice label.
78 Defienes the visibility of the slice label.
79
79
80 Default is not visible.
80 Default is not visible.
81
81
82 \sa label, labelPen, labelFont, labelArmLengthFactor
82 \sa label, labelBrush, labelFont, labelArmLengthFactor
83 */
83 */
84
84
85 /*!
85 /*!
86 \fn void QPieSlice::labelVisibleChanged()
86 \fn void QPieSlice::labelVisibleChanged()
87
87
88 This signal emitted when visibility of the slice label has changed.
88 This signal emitted when visibility of the slice label has changed.
89
89
90 \sa labelVisible
90 \sa labelVisible
91 */
91 */
92
92
93 /*!
93 /*!
94 \property QPieSlice::exploded
94 \property QPieSlice::exploded
95
95
96 Defines if the slice is exploded from the pie.
96 Defines if the slice is exploded from the pie.
97
97
98 \sa explodeDistanceFactor
98 \sa explodeDistanceFactor
99 */
99 */
100
100
101 /*!
101 /*!
102 \fn void QPieSlice::explodedChanged()
102 \fn void QPieSlice::explodedChanged()
103
103
104 This signal is emitted the the slice has been exploded from the pie or is returned back to the pie.
104 This signal is emitted the the slice has been exploded from the pie or is returned back to the pie.
105
105
106 \sa exploded
106 \sa exploded
107 */
107 */
108
108
109 /*!
109 /*!
110 \property QPieSlice::pen
110 \property QPieSlice::pen
111
111
112 Pen used to draw the slice border.
112 Pen used to draw the slice border.
113 */
113 */
114
114
115 /*!
115 /*!
116 \fn void QPieSlice::penChanged()
116 \fn void QPieSlice::penChanged()
117
117
118 This signal is emitted when the pen of the slice has changed.
118 This signal is emitted when the pen of the slice has changed.
119
119
120 \sa pen
120 \sa pen
121 */
121 */
122
122
123 /*!
123 /*!
124 \property QPieSlice::brush
124 \property QPieSlice::brush
125
125
126 Brush used to draw the slice.
126 Brush used to draw the slice.
127 */
127 */
128
128
129 /*!
129 /*!
130 \fn void QPieSlice::brushChanged()
130 \fn void QPieSlice::brushChanged()
131
131
132 This signal is emitted when the brush of the slice has changed.
132 This signal is emitted when the brush of the slice has changed.
133
133
134 \sa brush
134 \sa brush
135 */
135 */
136
136
137 /*!
137 /*!
138 \property QPieSlice::labelPen
138 \property QPieSlice::labelBrush
139
139
140 Pen used to draw label and label arm of the slice.
140 Pen used to draw label and label arm of the slice.
141
141
142 \sa label, labelVisible, labelFont, labelArmLengthFactor
142 \sa label, labelVisible, labelFont, labelArmLengthFactor
143 */
143 */
144
144
145 /*!
145 /*!
146 \fn void QPieSlice::labelPenChanged()
146 \fn void QPieSlice::labelBrushChanged()
147
147
148 This signal is emitted when the label pen of the slice has changed.
148 This signal is emitted when the label pen of the slice has changed.
149
149
150 \sa labelPen
150 \sa labelBrush
151 */
151 */
152
152
153 /*!
153 /*!
154 \property QPieSlice::labelFont
154 \property QPieSlice::labelFont
155
155
156 Font used for drawing label text.
156 Font used for drawing label text.
157
157
158 \sa label, labelVisible, labelArmLengthFactor
158 \sa label, labelVisible, labelArmLengthFactor
159 */
159 */
160
160
161 /*!
161 /*!
162 \fn void QPieSlice::labelFontChanged()
162 \fn void QPieSlice::labelFontChanged()
163
163
164 This signal is emitted when the label font of the slice has changed.
164 This signal is emitted when the label font of the slice has changed.
165
165
166 \sa labelFont
166 \sa labelFont
167 */
167 */
168
168
169 /*!
169 /*!
170 \property QPieSlice::labelArmLengthFactor
170 \property QPieSlice::labelArmLengthFactor
171
171
172 Defines the length of the label arm.
172 Defines the length of the label arm.
173
173
174 The factor is relative to pie radius. For example:
174 The factor is relative to pie radius. For example:
175 1.0 means the length is the same as the radius.
175 1.0 means the length is the same as the radius.
176 0.5 means the length is half of the radius.
176 0.5 means the length is half of the radius.
177
177
178 Default value is 0.15
178 Default value is 0.15
179
179
180 \sa label, labelVisible, labelPen, labelFont
180 \sa label, labelVisible, labelBrush, labelFont
181 */
181 */
182
182
183 /*!
183 /*!
184 \fn void QPieSlice::labelArmLengthFactorChanged()
184 \fn void QPieSlice::labelArmLengthFactorChanged()
185
185
186 This signal is emitted when the label arm factor of the slice has changed.
186 This signal is emitted when the label arm factor of the slice has changed.
187
187
188 \sa labelArmLengthFactor
188 \sa labelArmLengthFactor
189 */
189 */
190
190
191 /*!
191 /*!
192 \property QPieSlice::explodeDistanceFactor
192 \property QPieSlice::explodeDistanceFactor
193
193
194 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
194 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
195
195
196 The factor is relative to pie radius. For example:
196 The factor is relative to pie radius. For example:
197 1.0 means the distance is the same as the radius.
197 1.0 means the distance is the same as the radius.
198 0.5 means the distance is half of the radius.
198 0.5 means the distance is half of the radius.
199
199
200 Default value is 0.15
200 Default value is 0.15
201
201
202 \sa exploded
202 \sa exploded
203 */
203 */
204
204
205 /*!
205 /*!
206 \fn void QPieSlice::explodeDistanceFactorChanged()
206 \fn void QPieSlice::explodeDistanceFactorChanged()
207
207
208 This signal is emitted when the explode distance factor of the slice has changed.
208 This signal is emitted when the explode distance factor of the slice has changed.
209
209
210 \sa explodeDistanceFactor
210 \sa explodeDistanceFactor
211 */
211 */
212
212
213 /*!
213 /*!
214 \property QPieSlice::percentage
214 \property QPieSlice::percentage
215
215
216 Percentage of the slice compared to the sum of all slices in the series.
216 Percentage of the slice compared to the sum of all slices in the series.
217
217
218 The actual value ranges from 0.0 to 1.0.
218 The actual value ranges from 0.0 to 1.0.
219
219
220 Updated automatically once the slice is added to the series.
220 Updated automatically once the slice is added to the series.
221
221
222 \sa value, QPieSeries::sum
222 \sa value, QPieSeries::sum
223 */
223 */
224
224
225 /*!
225 /*!
226 \fn void QPieSlice::percentageChanged()
226 \fn void QPieSlice::percentageChanged()
227
227
228 This signal is emitted when the percentage of the slice has changed.
228 This signal is emitted when the percentage of the slice has changed.
229
229
230 \sa percentage
230 \sa percentage
231 */
231 */
232
232
233 /*!
233 /*!
234 \property QPieSlice::startAngle
234 \property QPieSlice::startAngle
235
235
236 Defines the starting angle of this slice in the series it belongs to.
236 Defines the starting angle of this slice in the series it belongs to.
237
237
238 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
238 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
239
239
240 Updated automatically once the slice is added to the series.
240 Updated automatically once the slice is added to the series.
241 */
241 */
242
242
243 /*!
243 /*!
244 \fn void QPieSlice::startAngleChanged()
244 \fn void QPieSlice::startAngleChanged()
245
245
246 This signal is emitted when the starting angle f the slice has changed.
246 This signal is emitted when the starting angle f the slice has changed.
247
247
248 \sa startAngle
248 \sa startAngle
249 */
249 */
250
250
251 /*!
251 /*!
252 \property QPieSlice::angleSpan
252 \property QPieSlice::angleSpan
253
253
254 Span of the slice in degrees.
254 Span of the slice in degrees.
255
255
256 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
256 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
257
257
258 Updated automatically once the slice is added to the series.
258 Updated automatically once the slice is added to the series.
259 */
259 */
260
260
261 /*!
261 /*!
262 \fn void QPieSlice::angleSpanChanged()
262 \fn void QPieSlice::angleSpanChanged()
263
263
264 This signal is emitted when the angle span of the slice has changed.
264 This signal is emitted when the angle span of the slice has changed.
265
265
266 \sa angleSpan
266 \sa angleSpan
267 */
267 */
268
268
269
269
270 /*!
270 /*!
271 \fn void QPieSlice::clicked()
271 \fn void QPieSlice::clicked()
272
272
273 This signal is emitted when user has clicked the slice.
273 This signal is emitted when user has clicked the slice.
274
274
275 \sa QPieSeries::clicked()
275 \sa QPieSeries::clicked()
276 */
276 */
277
277
278 /*!
278 /*!
279 \fn void QPieSlice::hovered(bool state)
279 \fn void QPieSlice::hovered(bool state)
280
280
281 This signal is emitted when user has hovered over or away from the slice.
281 This signal is emitted when user has hovered over or away from the slice.
282
282
283 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
283 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
284
284
285 \sa QPieSeries::hovered()
285 \sa QPieSeries::hovered()
286 */
286 */
287
287
288 /*!
288 /*!
289 Constructs an empty slice with a \a parent.
289 Constructs an empty slice with a \a parent.
290
290
291 \sa QPieSeries::append(), QPieSeries::insert()
291 \sa QPieSeries::append(), QPieSeries::insert()
292 */
292 */
293 QPieSlice::QPieSlice(QObject *parent)
293 QPieSlice::QPieSlice(QObject *parent)
294 :QObject(parent),
294 :QObject(parent),
295 d_ptr(new QPieSlicePrivate(this))
295 d_ptr(new QPieSlicePrivate(this))
296 {
296 {
297
297
298 }
298 }
299
299
300 /*!
300 /*!
301 Constructs an empty slice with given \a value, \a label and a \a parent.
301 Constructs an empty slice with given \a value, \a label and a \a parent.
302 \sa QPieSeries::append(), QPieSeries::insert()
302 \sa QPieSeries::append(), QPieSeries::insert()
303 */
303 */
304 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
304 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
305 :QObject(parent),
305 :QObject(parent),
306 d_ptr(new QPieSlicePrivate(this))
306 d_ptr(new QPieSlicePrivate(this))
307 {
307 {
308 setValue(value);
308 setValue(value);
309 setLabel(label);
309 setLabel(label);
310 }
310 }
311
311
312 /*!
312 /*!
313 Destroys the slice.
313 Destroys the slice.
314 User should not delete the slice if it has been added to the series.
314 User should not delete the slice if it has been added to the series.
315 */
315 */
316 QPieSlice::~QPieSlice()
316 QPieSlice::~QPieSlice()
317 {
317 {
318
318
319 }
319 }
320
320
321 void QPieSlice::setLabel(QString label)
321 void QPieSlice::setLabel(QString label)
322 {
322 {
323 if (d_ptr->m_data.m_labelText != label) {
323 if (d_ptr->m_data.m_labelText != label) {
324 d_ptr->m_data.m_labelText = label;
324 d_ptr->m_data.m_labelText = label;
325 emit labelChanged();
325 emit labelChanged();
326 }
326 }
327 }
327 }
328
328
329 QString QPieSlice::label() const
329 QString QPieSlice::label() const
330 {
330 {
331 return d_ptr->m_data.m_labelText;
331 return d_ptr->m_data.m_labelText;
332 }
332 }
333
333
334 void QPieSlice::setValue(qreal value)
334 void QPieSlice::setValue(qreal value)
335 {
335 {
336 value = qAbs(value); // negative values not allowed
336 value = qAbs(value); // negative values not allowed
337 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
337 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
338 d_ptr->m_data.m_value = value;
338 d_ptr->m_data.m_value = value;
339 emit valueChanged();
339 emit valueChanged();
340 }
340 }
341 }
341 }
342
342
343 qreal QPieSlice::value() const
343 qreal QPieSlice::value() const
344 {
344 {
345 return d_ptr->m_data.m_value;
345 return d_ptr->m_data.m_value;
346 }
346 }
347
347
348 void QPieSlice::setLabelVisible(bool visible)
348 void QPieSlice::setLabelVisible(bool visible)
349 {
349 {
350 if (d_ptr->m_data.m_isLabelVisible != visible) {
350 if (d_ptr->m_data.m_isLabelVisible != visible) {
351 d_ptr->m_data.m_isLabelVisible = visible;
351 d_ptr->m_data.m_isLabelVisible = visible;
352 emit labelVisibleChanged();
352 emit labelVisibleChanged();
353 }
353 }
354 }
354 }
355
355
356 bool QPieSlice::isLabelVisible() const
356 bool QPieSlice::isLabelVisible() const
357 {
357 {
358 return d_ptr->m_data.m_isLabelVisible;
358 return d_ptr->m_data.m_isLabelVisible;
359 }
359 }
360
360
361 void QPieSlice::setExploded(bool exploded)
361 void QPieSlice::setExploded(bool exploded)
362 {
362 {
363 if (d_ptr->m_data.m_isExploded != exploded) {
363 if (d_ptr->m_data.m_isExploded != exploded) {
364 d_ptr->m_data.m_isExploded = exploded;
364 d_ptr->m_data.m_isExploded = exploded;
365 emit explodedChanged();
365 emit explodedChanged();
366 }
366 }
367 }
367 }
368
368
369 bool QPieSlice::isExploded() const
369 bool QPieSlice::isExploded() const
370 {
370 {
371 return d_ptr->m_data.m_isExploded;
371 return d_ptr->m_data.m_isExploded;
372 }
372 }
373
373
374 void QPieSlice::setPen(const QPen &pen)
374 void QPieSlice::setPen(const QPen &pen)
375 {
375 {
376 d_ptr->setPen(pen, false);
376 d_ptr->setPen(pen, false);
377 }
377 }
378
378
379 QPen QPieSlice::pen() const
379 QPen QPieSlice::pen() const
380 {
380 {
381 return d_ptr->m_data.m_slicePen;
381 return d_ptr->m_data.m_slicePen;
382 }
382 }
383
383
384 void QPieSlice::setBrush(const QBrush &brush)
384 void QPieSlice::setBrush(const QBrush &brush)
385 {
385 {
386 d_ptr->setBrush(brush, false);
386 d_ptr->setBrush(brush, false);
387 }
387 }
388
388
389 QBrush QPieSlice::brush() const
389 QBrush QPieSlice::brush() const
390 {
390 {
391 return d_ptr->m_data.m_sliceBrush;
391 return d_ptr->m_data.m_sliceBrush;
392 }
392 }
393
393
394 void QPieSlice::setLabelPen(const QPen &pen)
394 void QPieSlice::setLabelBrush(const QBrush &brush)
395 {
395 {
396 d_ptr->setLabelPen(pen, false);
396 d_ptr->setLabelBrush(brush, false);
397 }
397 }
398
398
399 QPen QPieSlice::labelPen() const
399 QBrush QPieSlice::labelBrush() const
400 {
400 {
401 return d_ptr->m_data.m_labelPen;
401 return d_ptr->m_data.m_labelBrush;
402 }
402 }
403
403
404 void QPieSlice::setLabelFont(const QFont &font)
404 void QPieSlice::setLabelFont(const QFont &font)
405 {
405 {
406 d_ptr->setLabelFont(font, false);
406 d_ptr->setLabelFont(font, false);
407 }
407 }
408
408
409 QFont QPieSlice::labelFont() const
409 QFont QPieSlice::labelFont() const
410 {
410 {
411 return d_ptr->m_data.m_labelFont;
411 return d_ptr->m_data.m_labelFont;
412 }
412 }
413
413
414 void QPieSlice::setLabelArmLengthFactor(qreal factor)
414 void QPieSlice::setLabelArmLengthFactor(qreal factor)
415 {
415 {
416 if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) {
416 if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) {
417 d_ptr->m_data.m_labelArmLengthFactor = factor;
417 d_ptr->m_data.m_labelArmLengthFactor = factor;
418 emit labelArmLengthFactorChanged();
418 emit labelArmLengthFactorChanged();
419 }
419 }
420 }
420 }
421
421
422 qreal QPieSlice::labelArmLengthFactor() const
422 qreal QPieSlice::labelArmLengthFactor() const
423 {
423 {
424 return d_ptr->m_data.m_labelArmLengthFactor;
424 return d_ptr->m_data.m_labelArmLengthFactor;
425 }
425 }
426
426
427 void QPieSlice::setExplodeDistanceFactor(qreal factor)
427 void QPieSlice::setExplodeDistanceFactor(qreal factor)
428 {
428 {
429 if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) {
429 if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) {
430 d_ptr->m_data.m_explodeDistanceFactor = factor;
430 d_ptr->m_data.m_explodeDistanceFactor = factor;
431 emit explodeDistanceFactorChanged();
431 emit explodeDistanceFactorChanged();
432 }
432 }
433 }
433 }
434
434
435 qreal QPieSlice::explodeDistanceFactor() const
435 qreal QPieSlice::explodeDistanceFactor() const
436 {
436 {
437 return d_ptr->m_data.m_explodeDistanceFactor;
437 return d_ptr->m_data.m_explodeDistanceFactor;
438 }
438 }
439
439
440 qreal QPieSlice::percentage() const
440 qreal QPieSlice::percentage() const
441 {
441 {
442 return d_ptr->m_data.m_percentage;
442 return d_ptr->m_data.m_percentage;
443 }
443 }
444
444
445 qreal QPieSlice::startAngle() const
445 qreal QPieSlice::startAngle() const
446 {
446 {
447 return d_ptr->m_data.m_startAngle;
447 return d_ptr->m_data.m_startAngle;
448 }
448 }
449
449
450 qreal QPieSlice::angleSpan() const
450 qreal QPieSlice::angleSpan() const
451 {
451 {
452 return d_ptr->m_data.m_angleSpan;
452 return d_ptr->m_data.m_angleSpan;
453 }
453 }
454
454
455 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
455 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
456 :QObject(parent),
456 :QObject(parent),
457 q_ptr(parent)
457 q_ptr(parent)
458 {
458 {
459
459
460 }
460 }
461
461
462 QPieSlicePrivate::~QPieSlicePrivate()
462 QPieSlicePrivate::~QPieSlicePrivate()
463 {
463 {
464
464
465 }
465 }
466
466
467 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
467 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
468 {
468 {
469 return slice->d_func();
469 return slice->d_func();
470 }
470 }
471
471
472 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
472 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
473 {
473 {
474 if (m_data.m_slicePen != pen) {
474 if (m_data.m_slicePen != pen) {
475 m_data.m_slicePen = pen;
475 m_data.m_slicePen = pen;
476 m_data.m_slicePen.setThemed(themed);
476 m_data.m_slicePen.setThemed(themed);
477 emit q_ptr->penChanged();
477 emit q_ptr->penChanged();
478 }
478 }
479 }
479 }
480
480
481 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
481 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
482 {
482 {
483 if (m_data.m_sliceBrush != brush) {
483 if (m_data.m_sliceBrush != brush) {
484 m_data.m_sliceBrush = brush;
484 m_data.m_sliceBrush = brush;
485 m_data.m_sliceBrush.setThemed(themed);
485 m_data.m_sliceBrush.setThemed(themed);
486 emit q_ptr->brushChanged();
486 emit q_ptr->brushChanged();
487 }
487 }
488 }
488 }
489
489
490 void QPieSlicePrivate::setLabelPen(const QPen &pen, bool themed)
490 void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed)
491 {
491 {
492 if (m_data.m_labelPen != pen) {
492 if (m_data.m_labelBrush != brush) {
493 m_data.m_labelPen = pen;
493 m_data.m_labelBrush = brush;
494 m_data.m_labelPen.setThemed(themed);
494 m_data.m_labelBrush.setThemed(themed);
495 emit q_ptr->labelPenChanged();
495 emit q_ptr->labelBrushChanged();
496 }
496 }
497 }
497 }
498
498
499 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
499 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
500 {
500 {
501 if (m_data.m_labelFont != font) {
501 if (m_data.m_labelFont != font) {
502 m_data.m_labelFont = font;
502 m_data.m_labelFont = font;
503 m_data.m_labelFont.setThemed(themed);
503 m_data.m_labelFont.setThemed(themed);
504 emit q_ptr->labelFontChanged();
504 emit q_ptr->labelFontChanged();
505 }
505 }
506 }
506 }
507
507
508 void QPieSlicePrivate::setPercentage(qreal percentage)
508 void QPieSlicePrivate::setPercentage(qreal percentage)
509 {
509 {
510 if (!qFuzzyIsNull(m_data.m_percentage - percentage)) {
510 if (!qFuzzyIsNull(m_data.m_percentage - percentage)) {
511 m_data.m_percentage = percentage;
511 m_data.m_percentage = percentage;
512 emit q_ptr->percentageChanged();
512 emit q_ptr->percentageChanged();
513 }
513 }
514 }
514 }
515
515
516 void QPieSlicePrivate::setStartAngle(qreal angle)
516 void QPieSlicePrivate::setStartAngle(qreal angle)
517 {
517 {
518 if (!qFuzzyIsNull(m_data.m_startAngle - angle)) {
518 if (!qFuzzyIsNull(m_data.m_startAngle - angle)) {
519 m_data.m_startAngle = angle;
519 m_data.m_startAngle = angle;
520 emit q_ptr->startAngleChanged();
520 emit q_ptr->startAngleChanged();
521 }
521 }
522 }
522 }
523
523
524 void QPieSlicePrivate::setAngleSpan(qreal span)
524 void QPieSlicePrivate::setAngleSpan(qreal span)
525 {
525 {
526 if (!qFuzzyIsNull(m_data.m_angleSpan - span)) {
526 if (!qFuzzyIsNull(m_data.m_angleSpan - span)) {
527 m_data.m_angleSpan = span;
527 m_data.m_angleSpan = span;
528 emit q_ptr->angleSpanChanged();
528 emit q_ptr->angleSpanChanged();
529 }
529 }
530 }
530 }
531
531
532 QTCOMMERCIALCHART_END_NAMESPACE
532 QTCOMMERCIALCHART_END_NAMESPACE
533
533
534 QTCOMMERCIALCHART_USE_NAMESPACE
534 QTCOMMERCIALCHART_USE_NAMESPACE
535 #include "moc_qpieslice.cpp"
535 #include "moc_qpieslice.cpp"
536 #include "moc_qpieslice_p.cpp"
536 #include "moc_qpieslice_p.cpp"
@@ -1,114 +1,114
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QPIESLICE_H
21 #ifndef QPIESLICE_H
22 #define QPIESLICE_H
22 #define QPIESLICE_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QObject>
25 #include <QObject>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28 #include <QFont>
28 #include <QFont>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 class QPieSlicePrivate;
31 class QPieSlicePrivate;
32
32
33 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
33 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
36 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
37 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
37 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
38 Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged)
38 Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged)
39 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded NOTIFY explodedChanged)
39 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded NOTIFY explodedChanged)
40 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
40 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
41 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
41 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
42 Q_PROPERTY(QPen labelPen READ labelPen WRITE setLabelPen NOTIFY labelPenChanged)
42 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
43 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
43 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
44 Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor)
44 Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor)
45 Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor)
45 Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor)
46 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
46 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
47 Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged)
47 Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged)
48 Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged)
48 Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged)
49
49
50 public:
50 public:
51 explicit QPieSlice(QObject *parent = 0);
51 explicit QPieSlice(QObject *parent = 0);
52 QPieSlice(QString label, qreal value, QObject *parent = 0);
52 QPieSlice(QString label, qreal value, QObject *parent = 0);
53 virtual ~QPieSlice();
53 virtual ~QPieSlice();
54
54
55 void setLabel(QString label);
55 void setLabel(QString label);
56 QString label() const;
56 QString label() const;
57
57
58 void setValue(qreal value);
58 void setValue(qreal value);
59 qreal value() const;
59 qreal value() const;
60
60
61 void setLabelVisible(bool visible = true);
61 void setLabelVisible(bool visible = true);
62 bool isLabelVisible() const;
62 bool isLabelVisible() const;
63
63
64 void setExploded(bool exploded = true);
64 void setExploded(bool exploded = true);
65 bool isExploded() const;
65 bool isExploded() const;
66
66
67 void setPen(const QPen &pen);
67 void setPen(const QPen &pen);
68 QPen pen() const;
68 QPen pen() const;
69
69
70 void setBrush(const QBrush &brush);
70 void setBrush(const QBrush &brush);
71 QBrush brush() const;
71 QBrush brush() const;
72
72
73 void setLabelPen(const QPen &pen);
73 void setLabelBrush(const QBrush &brush);
74 QPen labelPen() const;
74 QBrush labelBrush() const;
75
75
76 void setLabelFont(const QFont &font);
76 void setLabelFont(const QFont &font);
77 QFont labelFont() const;
77 QFont labelFont() const;
78
78
79 void setLabelArmLengthFactor(qreal factor);
79 void setLabelArmLengthFactor(qreal factor);
80 qreal labelArmLengthFactor() const;
80 qreal labelArmLengthFactor() const;
81
81
82 void setExplodeDistanceFactor(qreal factor);
82 void setExplodeDistanceFactor(qreal factor);
83 qreal explodeDistanceFactor() const;
83 qreal explodeDistanceFactor() const;
84
84
85 qreal percentage() const;
85 qreal percentage() const;
86 qreal startAngle() const;
86 qreal startAngle() const;
87 qreal angleSpan() const;
87 qreal angleSpan() const;
88
88
89 Q_SIGNALS:
89 Q_SIGNALS:
90 void labelChanged();
90 void labelChanged();
91 void valueChanged();
91 void valueChanged();
92 void labelVisibleChanged();
92 void labelVisibleChanged();
93 void explodedChanged();
93 void explodedChanged();
94 void penChanged();
94 void penChanged();
95 void brushChanged();
95 void brushChanged();
96 void labelPenChanged();
96 void labelBrushChanged();
97 void labelFontChanged();
97 void labelFontChanged();
98 void labelArmLengthFactorChanged();
98 void labelArmLengthFactorChanged();
99 void explodeDistanceFactorChanged();
99 void explodeDistanceFactorChanged();
100 void percentageChanged();
100 void percentageChanged();
101 void startAngleChanged();
101 void startAngleChanged();
102 void angleSpanChanged();
102 void angleSpanChanged();
103 void clicked();
103 void clicked();
104 void hovered(bool state);
104 void hovered(bool state);
105
105
106 private:
106 private:
107 QPieSlicePrivate * const d_ptr;
107 QPieSlicePrivate * const d_ptr;
108 Q_DECLARE_PRIVATE(QPieSlice)
108 Q_DECLARE_PRIVATE(QPieSlice)
109 Q_DISABLE_COPY(QPieSlice)
109 Q_DISABLE_COPY(QPieSlice)
110 };
110 };
111
111
112 QTCOMMERCIALCHART_END_NAMESPACE
112 QTCOMMERCIALCHART_END_NAMESPACE
113
113
114 #endif // QPIESLICE_H
114 #endif // QPIESLICE_H
@@ -1,43 +1,43
1 #ifndef QPIESLICE_P_H
1 #ifndef QPIESLICE_P_H
2 #define QPIESLICE_P_H
2 #define QPIESLICE_P_H
3
3
4 #include <QObject>
4 #include <QObject>
5 #include "qpieslice.h"
5 #include "qpieslice.h"
6 #include "pieslicedata_p.h"
6 #include "pieslicedata_p.h"
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QPieSlicePrivate : public QObject
10 class QPieSlicePrivate : public QObject
11 {
11 {
12 Q_OBJECT
12 Q_OBJECT
13
13
14 public:
14 public:
15 QPieSlicePrivate(QPieSlice *parent);
15 QPieSlicePrivate(QPieSlice *parent);
16 ~QPieSlicePrivate();
16 ~QPieSlicePrivate();
17
17
18 static QPieSlicePrivate* fromSlice(QPieSlice *slice);
18 static QPieSlicePrivate* fromSlice(QPieSlice *slice);
19
19
20 void setPen(const QPen &pen, bool themed);
20 void setPen(const QPen &pen, bool themed);
21 void setBrush(const QBrush &brush, bool themed);
21 void setBrush(const QBrush &brush, bool themed);
22 void setLabelPen(const QPen &pen, bool themed);
22 void setLabelBrush(const QBrush &brush, bool themed);
23 void setLabelFont(const QFont &font, bool themed);
23 void setLabelFont(const QFont &font, bool themed);
24
24
25 void setPercentage(qreal percentage);
25 void setPercentage(qreal percentage);
26 void setStartAngle(qreal angle);
26 void setStartAngle(qreal angle);
27 void setAngleSpan(qreal span);
27 void setAngleSpan(qreal span);
28
28
29 private:
29 private:
30 PieSliceData m_data;
30 PieSliceData m_data;
31
31
32 private:
32 private:
33 friend class QPieSeriesPrivate;
33 friend class QPieSeriesPrivate;
34 friend class ChartTheme;
34 friend class ChartTheme;
35 friend class PieChartItem;
35 friend class PieChartItem;
36
36
37 QPieSlice * const q_ptr;
37 QPieSlice * const q_ptr;
38 Q_DECLARE_PUBLIC(QPieSlice)
38 Q_DECLARE_PUBLIC(QPieSlice)
39 };
39 };
40
40
41 QTCOMMERCIALCHART_END_NAMESPACE
41 QTCOMMERCIALCHART_END_NAMESPACE
42
42
43 #endif // QPIESLICE_P_H
43 #endif // QPIESLICE_P_H
@@ -1,436 +1,418
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qbarset.h>
22 #include <qbarset.h>
23
23
24 QTCOMMERCIALCHART_USE_NAMESPACE
24 QTCOMMERCIALCHART_USE_NAMESPACE
25
25
26 class tst_QBarSet : public QObject
26 class tst_QBarSet : public QObject
27 {
27 {
28 Q_OBJECT
28 Q_OBJECT
29
29
30 public slots:
30 public slots:
31 void initTestCase();
31 void initTestCase();
32 void cleanupTestCase();
32 void cleanupTestCase();
33 void init();
33 void init();
34 void cleanup();
34 void cleanup();
35
35
36 private slots:
36 private slots:
37 void qbarset_data();
37 void qbarset_data();
38 void qbarset();
38 void qbarset();
39 void name_data();
39 void name_data();
40 void name();
40 void name();
41 void append_data();
41 void append_data();
42 void append();
42 void append();
43 void appendOperator_data();
43 void appendOperator_data();
44 void appendOperator();
44 void appendOperator();
45 void insert_data();
45 void insert_data();
46 void insert();
46 void insert();
47 void remove_data();
47 void remove_data();
48 void remove();
48 void remove();
49 void replace_data();
49 void replace_data();
50 void replace();
50 void replace();
51 void at_data();
51 void at_data();
52 void at();
52 void at();
53 void atOperator_data();
53 void atOperator_data();
54 void atOperator();
54 void atOperator();
55 void count_data();
55 void count_data();
56 void count();
56 void count();
57 void sum_data();
57 void sum_data();
58 void sum();
58 void sum();
59 void setPen_data();
59 void setPen_data();
60 void setPen();
60 void setPen();
61 void setBrush_data();
61 void setBrush_data();
62 void setBrush();
62 void setBrush();
63 void setLabelPen_data();
64 void setLabelPen();
65 void setLabelBrush_data();
63 void setLabelBrush_data();
66 void setLabelBrush();
64 void setLabelBrush();
67 void setLabelFont_data();
65 void setLabelFont_data();
68 void setLabelFont();
66 void setLabelFont();
69
67
70 private:
68 private:
71 QBarSet* m_barset;
69 QBarSet* m_barset;
72 };
70 };
73
71
74 void tst_QBarSet::initTestCase()
72 void tst_QBarSet::initTestCase()
75 {
73 {
76 }
74 }
77
75
78 void tst_QBarSet::cleanupTestCase()
76 void tst_QBarSet::cleanupTestCase()
79 {
77 {
80 }
78 }
81
79
82 void tst_QBarSet::init()
80 void tst_QBarSet::init()
83 {
81 {
84 m_barset = new QBarSet(QString("Name"));
82 m_barset = new QBarSet(QString("Name"));
85 }
83 }
86
84
87 void tst_QBarSet::cleanup()
85 void tst_QBarSet::cleanup()
88 {
86 {
89 delete m_barset;
87 delete m_barset;
90 m_barset = 0;
88 m_barset = 0;
91 }
89 }
92
90
93 void tst_QBarSet::qbarset_data()
91 void tst_QBarSet::qbarset_data()
94 {
92 {
95 }
93 }
96
94
97 void tst_QBarSet::qbarset()
95 void tst_QBarSet::qbarset()
98 {
96 {
99 QBarSet barset(QString("Name"));
97 QBarSet barset(QString("Name"));
100 QCOMPARE(barset.name(), QString("Name"));
98 QCOMPARE(barset.name(), QString("Name"));
101 QCOMPARE(barset.count(), 0);
99 QCOMPARE(barset.count(), 0);
102 QVERIFY(qFuzzyIsNull(barset.sum()));
100 QVERIFY(qFuzzyIsNull(barset.sum()));
103 }
101 }
104
102
105 void tst_QBarSet::name_data()
103 void tst_QBarSet::name_data()
106 {
104 {
107 QTest::addColumn<QString> ("name");
105 QTest::addColumn<QString> ("name");
108 QTest::addColumn<QString> ("result");
106 QTest::addColumn<QString> ("result");
109 QTest::newRow("name0") << QString("name0") << QString("name0");
107 QTest::newRow("name0") << QString("name0") << QString("name0");
110 QTest::newRow("name1") << QString("name1") << QString("name1");
108 QTest::newRow("name1") << QString("name1") << QString("name1");
111 }
109 }
112
110
113 void tst_QBarSet::name()
111 void tst_QBarSet::name()
114 {
112 {
115 QFETCH(QString, name);
113 QFETCH(QString, name);
116 QFETCH(QString, result);
114 QFETCH(QString, result);
117
115
118 m_barset->setName(name);
116 m_barset->setName(name);
119 QCOMPARE(m_barset->name(), result);
117 QCOMPARE(m_barset->name(), result);
120 }
118 }
121
119
122 void tst_QBarSet::append_data()
120 void tst_QBarSet::append_data()
123 {
121 {
124 QTest::addColumn<int> ("count");
122 QTest::addColumn<int> ("count");
125 QTest::newRow("0") << 0;
123 QTest::newRow("0") << 0;
126 QTest::newRow("5") << 5;
124 QTest::newRow("5") << 5;
127 QTest::newRow("100") << 100;
125 QTest::newRow("100") << 100;
128 QTest::newRow("1000") << 1000;
126 QTest::newRow("1000") << 1000;
129 }
127 }
130
128
131 void tst_QBarSet::append()
129 void tst_QBarSet::append()
132 {
130 {
133 QFETCH(int, count);
131 QFETCH(int, count);
134
132
135 QCOMPARE(m_barset->count(), 0);
133 QCOMPARE(m_barset->count(), 0);
136 QVERIFY(qFuzzyIsNull(m_barset->sum()));
134 QVERIFY(qFuzzyIsNull(m_barset->sum()));
137
135
138 qreal sum(0.0);
136 qreal sum(0.0);
139 qreal value(0.0);
137 qreal value(0.0);
140
138
141 for (int i=0; i<count; i++) {
139 for (int i=0; i<count; i++) {
142 m_barset->append(value);
140 m_barset->append(value);
143 QCOMPARE(m_barset->at(i).y(), value);
141 QCOMPARE(m_barset->at(i).y(), value);
144 sum += value;
142 sum += value;
145 value += 1.0;
143 value += 1.0;
146 }
144 }
147
145
148 QCOMPARE(m_barset->count(), count);
146 QCOMPARE(m_barset->count(), count);
149 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
147 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
150 }
148 }
151
149
152 void tst_QBarSet::appendOperator_data()
150 void tst_QBarSet::appendOperator_data()
153 {
151 {
154 append_data();
152 append_data();
155 }
153 }
156
154
157 void tst_QBarSet::appendOperator()
155 void tst_QBarSet::appendOperator()
158 {
156 {
159 QFETCH(int, count);
157 QFETCH(int, count);
160
158
161 QCOMPARE(m_barset->count(), 0);
159 QCOMPARE(m_barset->count(), 0);
162 QVERIFY(qFuzzyIsNull(m_barset->sum()));
160 QVERIFY(qFuzzyIsNull(m_barset->sum()));
163
161
164 qreal sum(0.0);
162 qreal sum(0.0);
165 qreal value(0.0);
163 qreal value(0.0);
166
164
167 for (int i=0; i<count; i++) {
165 for (int i=0; i<count; i++) {
168 *m_barset << value;
166 *m_barset << value;
169 QCOMPARE(m_barset->at(i).y(), value);
167 QCOMPARE(m_barset->at(i).y(), value);
170 sum += value;
168 sum += value;
171 value += 1.0;
169 value += 1.0;
172 }
170 }
173
171
174 QCOMPARE(m_barset->count(), count);
172 QCOMPARE(m_barset->count(), count);
175 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
173 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
176 }
174 }
177
175
178 void tst_QBarSet::insert_data()
176 void tst_QBarSet::insert_data()
179 {
177 {
180 }
178 }
181
179
182 void tst_QBarSet::insert()
180 void tst_QBarSet::insert()
183 {
181 {
184 QCOMPARE(m_barset->count(), 0);
182 QCOMPARE(m_barset->count(), 0);
185 QVERIFY(qFuzzyIsNull(m_barset->sum()));
183 QVERIFY(qFuzzyIsNull(m_barset->sum()));
186
184
187 m_barset->insert(0, 1.0); // 1.0
185 m_barset->insert(0, 1.0); // 1.0
188 QCOMPARE(m_barset->at(0).y(), 1.0);
186 QCOMPARE(m_barset->at(0).y(), 1.0);
189 QCOMPARE(m_barset->count(), 1);
187 QCOMPARE(m_barset->count(), 1);
190 QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0));
188 QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0));
191
189
192 m_barset->insert(0, 2.0); // 2.0 1.0
190 m_barset->insert(0, 2.0); // 2.0 1.0
193 QCOMPARE(m_barset->at(0).y(), 2.0);
191 QCOMPARE(m_barset->at(0).y(), 2.0);
194 QCOMPARE(m_barset->at(1).y(), 1.0);
192 QCOMPARE(m_barset->at(1).y(), 1.0);
195 QCOMPARE(m_barset->count(), 2);
193 QCOMPARE(m_barset->count(), 2);
196 QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0));
194 QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0));
197
195
198 m_barset->insert(1, 3.0); // 2.0 3.0 1.0
196 m_barset->insert(1, 3.0); // 2.0 3.0 1.0
199 QCOMPARE(m_barset->at(1).y(), 3.0);
197 QCOMPARE(m_barset->at(1).y(), 3.0);
200 QCOMPARE(m_barset->at(0).y(), 2.0);
198 QCOMPARE(m_barset->at(0).y(), 2.0);
201 QCOMPARE(m_barset->at(2).y(), 1.0);
199 QCOMPARE(m_barset->at(2).y(), 1.0);
202 QCOMPARE(m_barset->count(), 3);
200 QCOMPARE(m_barset->count(), 3);
203 QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0));
201 QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0));
204 }
202 }
205
203
206 void tst_QBarSet::remove_data()
204 void tst_QBarSet::remove_data()
207 {
205 {
208 }
206 }
209
207
210 void tst_QBarSet::remove()
208 void tst_QBarSet::remove()
211 {
209 {
212 QCOMPARE(m_barset->count(), 0);
210 QCOMPARE(m_barset->count(), 0);
213 QVERIFY(qFuzzyIsNull(m_barset->sum()));
211 QVERIFY(qFuzzyIsNull(m_barset->sum()));
214
212
215 m_barset->append(1.0);
213 m_barset->append(1.0);
216 m_barset->append(2.0);
214 m_barset->append(2.0);
217 m_barset->append(3.0);
215 m_barset->append(3.0);
218 m_barset->append(4.0);
216 m_barset->append(4.0);
219
217
220 QCOMPARE(m_barset->count(), 4);
218 QCOMPARE(m_barset->count(), 4);
221 QCOMPARE(m_barset->sum(), 10.0);
219 QCOMPARE(m_barset->sum(), 10.0);
222
220
223 m_barset->remove(2); // 1.0 2.0 4.0
221 m_barset->remove(2); // 1.0 2.0 4.0
224 QCOMPARE(m_barset->at(0).y(), 1.0);
222 QCOMPARE(m_barset->at(0).y(), 1.0);
225 QCOMPARE(m_barset->at(1).y(), 2.0);
223 QCOMPARE(m_barset->at(1).y(), 2.0);
226 QCOMPARE(m_barset->at(2).y(), 4.0);
224 QCOMPARE(m_barset->at(2).y(), 4.0);
227 QCOMPARE(m_barset->count(), 3);
225 QCOMPARE(m_barset->count(), 3);
228 QCOMPARE(m_barset->sum(), 7.0);
226 QCOMPARE(m_barset->sum(), 7.0);
229
227
230 m_barset->remove(0); // 2.0 4.0
228 m_barset->remove(0); // 2.0 4.0
231 QCOMPARE(m_barset->at(0).y(), 2.0);
229 QCOMPARE(m_barset->at(0).y(), 2.0);
232 QCOMPARE(m_barset->at(1).y(), 4.0);
230 QCOMPARE(m_barset->at(1).y(), 4.0);
233 QCOMPARE(m_barset->count(), 2);
231 QCOMPARE(m_barset->count(), 2);
234 QCOMPARE(m_barset->sum(), 6.0);
232 QCOMPARE(m_barset->sum(), 6.0);
235 }
233 }
236
234
237 void tst_QBarSet::replace_data()
235 void tst_QBarSet::replace_data()
238 {
236 {
239
237
240 }
238 }
241
239
242 void tst_QBarSet::replace()
240 void tst_QBarSet::replace()
243 {
241 {
244 QCOMPARE(m_barset->count(), 0);
242 QCOMPARE(m_barset->count(), 0);
245 QVERIFY(qFuzzyIsNull(m_barset->sum()));
243 QVERIFY(qFuzzyIsNull(m_barset->sum()));
246
244
247 m_barset->append(1.0);
245 m_barset->append(1.0);
248 m_barset->append(2.0);
246 m_barset->append(2.0);
249 m_barset->append(3.0);
247 m_barset->append(3.0);
250 m_barset->append(4.0);
248 m_barset->append(4.0);
251
249
252 QCOMPARE(m_barset->count(), 4);
250 QCOMPARE(m_barset->count(), 4);
253 QCOMPARE(m_barset->sum(), 10.0);
251 QCOMPARE(m_barset->sum(), 10.0);
254
252
255 m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0
253 m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0
256 QCOMPARE(m_barset->count(), 4);
254 QCOMPARE(m_barset->count(), 4);
257 QCOMPARE(m_barset->sum(), 14.0);
255 QCOMPARE(m_barset->sum(), 14.0);
258 QCOMPARE(m_barset->at(0).y(), 5.0);
256 QCOMPARE(m_barset->at(0).y(), 5.0);
259
257
260 m_barset->replace(3, 6.0);
258 m_barset->replace(3, 6.0);
261 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
259 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
262 QCOMPARE(m_barset->sum(), 16.0);
260 QCOMPARE(m_barset->sum(), 16.0);
263 QCOMPARE(m_barset->at(0).y(), 5.0);
261 QCOMPARE(m_barset->at(0).y(), 5.0);
264 QCOMPARE(m_barset->at(1).y(), 2.0);
262 QCOMPARE(m_barset->at(1).y(), 2.0);
265 QCOMPARE(m_barset->at(2).y(), 3.0);
263 QCOMPARE(m_barset->at(2).y(), 3.0);
266 QCOMPARE(m_barset->at(3).y(), 6.0);
264 QCOMPARE(m_barset->at(3).y(), 6.0);
267 }
265 }
268
266
269 void tst_QBarSet::at_data()
267 void tst_QBarSet::at_data()
270 {
268 {
271
269
272 }
270 }
273
271
274 void tst_QBarSet::at()
272 void tst_QBarSet::at()
275 {
273 {
276 QCOMPARE(m_barset->count(), 0);
274 QCOMPARE(m_barset->count(), 0);
277 QVERIFY(qFuzzyIsNull(m_barset->sum()));
275 QVERIFY(qFuzzyIsNull(m_barset->sum()));
278
276
279 m_barset->append(1.0);
277 m_barset->append(1.0);
280 m_barset->append(2.0);
278 m_barset->append(2.0);
281 m_barset->append(3.0);
279 m_barset->append(3.0);
282 m_barset->append(4.0);
280 m_barset->append(4.0);
283
281
284 QCOMPARE(m_barset->at(0).y(), 1.0);
282 QCOMPARE(m_barset->at(0).y(), 1.0);
285 QCOMPARE(m_barset->at(1).y(), 2.0);
283 QCOMPARE(m_barset->at(1).y(), 2.0);
286 QCOMPARE(m_barset->at(2).y(), 3.0);
284 QCOMPARE(m_barset->at(2).y(), 3.0);
287 QCOMPARE(m_barset->at(3).y(), 4.0);
285 QCOMPARE(m_barset->at(3).y(), 4.0);
288 }
286 }
289
287
290 void tst_QBarSet::atOperator_data()
288 void tst_QBarSet::atOperator_data()
291 {
289 {
292
290
293 }
291 }
294
292
295 void tst_QBarSet::atOperator()
293 void tst_QBarSet::atOperator()
296 {
294 {
297 QCOMPARE(m_barset->count(), 0);
295 QCOMPARE(m_barset->count(), 0);
298 QVERIFY(qFuzzyIsNull(m_barset->sum()));
296 QVERIFY(qFuzzyIsNull(m_barset->sum()));
299
297
300 m_barset->append(1.0);
298 m_barset->append(1.0);
301 m_barset->append(2.0);
299 m_barset->append(2.0);
302 m_barset->append(3.0);
300 m_barset->append(3.0);
303 m_barset->append(4.0);
301 m_barset->append(4.0);
304
302
305 QCOMPARE(m_barset->operator [](0).y(), 1.0);
303 QCOMPARE(m_barset->operator [](0).y(), 1.0);
306 QCOMPARE(m_barset->operator [](1).y(), 2.0);
304 QCOMPARE(m_barset->operator [](1).y(), 2.0);
307 QCOMPARE(m_barset->operator [](2).y(), 3.0);
305 QCOMPARE(m_barset->operator [](2).y(), 3.0);
308 QCOMPARE(m_barset->operator [](3).y(), 4.0);
306 QCOMPARE(m_barset->operator [](3).y(), 4.0);
309 }
307 }
310
308
311 void tst_QBarSet::count_data()
309 void tst_QBarSet::count_data()
312 {
310 {
313
311
314 }
312 }
315
313
316 void tst_QBarSet::count()
314 void tst_QBarSet::count()
317 {
315 {
318 QCOMPARE(m_barset->count(), 0);
316 QCOMPARE(m_barset->count(), 0);
319 QVERIFY(qFuzzyIsNull(m_barset->sum()));
317 QVERIFY(qFuzzyIsNull(m_barset->sum()));
320
318
321 m_barset->append(1.0);
319 m_barset->append(1.0);
322 QCOMPARE(m_barset->count(),1);
320 QCOMPARE(m_barset->count(),1);
323 m_barset->append(2.0);
321 m_barset->append(2.0);
324 QCOMPARE(m_barset->count(),2);
322 QCOMPARE(m_barset->count(),2);
325 m_barset->append(3.0);
323 m_barset->append(3.0);
326 QCOMPARE(m_barset->count(),3);
324 QCOMPARE(m_barset->count(),3);
327 m_barset->append(4.0);
325 m_barset->append(4.0);
328 QCOMPARE(m_barset->count(),4);
326 QCOMPARE(m_barset->count(),4);
329 }
327 }
330
328
331 void tst_QBarSet::sum_data()
329 void tst_QBarSet::sum_data()
332 {
330 {
333
331
334 }
332 }
335
333
336 void tst_QBarSet::sum()
334 void tst_QBarSet::sum()
337 {
335 {
338 QCOMPARE(m_barset->count(), 0);
336 QCOMPARE(m_barset->count(), 0);
339 QVERIFY(qFuzzyIsNull(m_barset->sum()));
337 QVERIFY(qFuzzyIsNull(m_barset->sum()));
340
338
341 m_barset->append(1.0);
339 m_barset->append(1.0);
342 QVERIFY(qFuzzyCompare(m_barset->sum(),1.0));
340 QVERIFY(qFuzzyCompare(m_barset->sum(),1.0));
343 m_barset->append(2.0);
341 m_barset->append(2.0);
344 QVERIFY(qFuzzyCompare(m_barset->sum(),3.0));
342 QVERIFY(qFuzzyCompare(m_barset->sum(),3.0));
345 m_barset->append(3.0);
343 m_barset->append(3.0);
346 QVERIFY(qFuzzyCompare(m_barset->sum(),6.0));
344 QVERIFY(qFuzzyCompare(m_barset->sum(),6.0));
347 m_barset->append(4.0);
345 m_barset->append(4.0);
348 QVERIFY(qFuzzyCompare(m_barset->sum(),10.0));
346 QVERIFY(qFuzzyCompare(m_barset->sum(),10.0));
349 }
347 }
350
348
351 void tst_QBarSet::setPen_data()
349 void tst_QBarSet::setPen_data()
352 {
350 {
353
351
354 }
352 }
355
353
356 void tst_QBarSet::setPen()
354 void tst_QBarSet::setPen()
357 {
355 {
358 QVERIFY(m_barset->pen() == QPen());
356 QVERIFY(m_barset->pen() == QPen());
359
357
360 QPen pen;
358 QPen pen;
361 pen.setColor(QColor(128,128,128,128));
359 pen.setColor(QColor(128,128,128,128));
362 m_barset->setPen(pen);
360 m_barset->setPen(pen);
363
361
364 QVERIFY(m_barset->pen() == pen);
362 QVERIFY(m_barset->pen() == pen);
365 }
363 }
366
364
367 void tst_QBarSet::setBrush_data()
365 void tst_QBarSet::setBrush_data()
368 {
366 {
369
367
370 }
368 }
371
369
372 void tst_QBarSet::setBrush()
370 void tst_QBarSet::setBrush()
373 {
371 {
374 QVERIFY(m_barset->brush() == QBrush());
372 QVERIFY(m_barset->brush() == QBrush());
375
373
376 QBrush brush;
374 QBrush brush;
377 brush.setColor(QColor(128,128,128,128));
375 brush.setColor(QColor(128,128,128,128));
378 m_barset->setBrush(brush);
376 m_barset->setBrush(brush);
379
377
380 QVERIFY(m_barset->brush() == brush);
378 QVERIFY(m_barset->brush() == brush);
381 }
379 }
382
380
383 void tst_QBarSet::setLabelPen_data()
384 {
385
386 }
387
388 void tst_QBarSet::setLabelPen()
389 {
390 QVERIFY(m_barset->labelPen() == QPen());
391
392 QPen pen;
393 pen.setColor(QColor(128,128,128,128));
394 m_barset->setLabelPen(pen);
395
396 QVERIFY(m_barset->labelPen() == pen);
397 }
398
399 void tst_QBarSet::setLabelBrush_data()
381 void tst_QBarSet::setLabelBrush_data()
400 {
382 {
401
383
402 }
384 }
403
385
404 void tst_QBarSet::setLabelBrush()
386 void tst_QBarSet::setLabelBrush()
405 {
387 {
406 QVERIFY(m_barset->labelBrush() == QBrush());
388 QVERIFY(m_barset->labelBrush() == QBrush());
407
389
408 QBrush brush;
390 QBrush brush;
409 brush.setColor(QColor(128,128,128,128));
391 brush.setColor(QColor(128,128,128,128));
410 m_barset->setLabelBrush(brush);
392 m_barset->setLabelBrush(brush);
411
393
412 QVERIFY(m_barset->labelBrush() == brush);
394 QVERIFY(m_barset->labelBrush() == brush);
413 }
395 }
414
396
415 void tst_QBarSet::setLabelFont_data()
397 void tst_QBarSet::setLabelFont_data()
416 {
398 {
417
399
418 }
400 }
419
401
420 void tst_QBarSet::setLabelFont()
402 void tst_QBarSet::setLabelFont()
421 {
403 {
422 QVERIFY(m_barset->labelFont() == QFont());
404 QVERIFY(m_barset->labelFont() == QFont());
423
405
424 QFont font;
406 QFont font;
425 font.setBold(true);
407 font.setBold(true);
426 font.setItalic(true);
408 font.setItalic(true);
427 m_barset->setLabelFont(font);
409 m_barset->setLabelFont(font);
428
410
429 QVERIFY(m_barset->labelFont() == font);
411 QVERIFY(m_barset->labelFont() == font);
430 }
412 }
431
413
432
414
433 QTEST_MAIN(tst_QBarSet)
415 QTEST_MAIN(tst_QBarSet)
434
416
435 #include "tst_qbarset.moc"
417 #include "tst_qbarset.moc"
436
418
@@ -1,292 +1,292
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <tst_definitions.h>
22 #include <tst_definitions.h>
23 #include <qchartview.h>
23 #include <qchartview.h>
24 #include <qchart.h>
24 #include <qchart.h>
25 #include <qpieslice.h>
25 #include <qpieslice.h>
26 #include <qpieseries.h>
26 #include <qpieseries.h>
27
27
28 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
29
29
30 class tst_qpieslice : public QObject
30 class tst_qpieslice : public QObject
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33
33
34 public slots:
34 public slots:
35 void initTestCase();
35 void initTestCase();
36 void cleanupTestCase();
36 void cleanupTestCase();
37 void init();
37 void init();
38 void cleanup();
38 void cleanup();
39
39
40 private slots:
40 private slots:
41 void construction();
41 void construction();
42 void changedSignals();
42 void changedSignals();
43 void customize();
43 void customize();
44 void mouseClick();
44 void mouseClick();
45 void mouseHover();
45 void mouseHover();
46
46
47 private:
47 private:
48
48
49
49
50 private:
50 private:
51
51
52 };
52 };
53
53
54 void tst_qpieslice::initTestCase()
54 void tst_qpieslice::initTestCase()
55 {
55 {
56 }
56 }
57
57
58 void tst_qpieslice::cleanupTestCase()
58 void tst_qpieslice::cleanupTestCase()
59 {
59 {
60 }
60 }
61
61
62 void tst_qpieslice::init()
62 void tst_qpieslice::init()
63 {
63 {
64
64
65 }
65 }
66
66
67 void tst_qpieslice::cleanup()
67 void tst_qpieslice::cleanup()
68 {
68 {
69
69
70 }
70 }
71
71
72 void tst_qpieslice::construction()
72 void tst_qpieslice::construction()
73 {
73 {
74 // no params
74 // no params
75 QPieSlice slice1;
75 QPieSlice slice1;
76 QCOMPARE(slice1.value(), 0.0);
76 QCOMPARE(slice1.value(), 0.0);
77 QVERIFY(slice1.label().isEmpty());
77 QVERIFY(slice1.label().isEmpty());
78 QVERIFY(!slice1.isLabelVisible());
78 QVERIFY(!slice1.isLabelVisible());
79 QVERIFY(!slice1.isExploded());
79 QVERIFY(!slice1.isExploded());
80 QCOMPARE(slice1.pen(), QPen());
80 QCOMPARE(slice1.pen(), QPen());
81 QCOMPARE(slice1.brush(), QBrush());
81 QCOMPARE(slice1.brush(), QBrush());
82 QCOMPARE(slice1.labelPen(), QPen());
82 QCOMPARE(slice1.labelBrush(), QBrush());
83 QCOMPARE(slice1.labelFont(), QFont());
83 QCOMPARE(slice1.labelFont(), QFont());
84 QCOMPARE(slice1.labelArmLengthFactor(), 0.15); // default value
84 QCOMPARE(slice1.labelArmLengthFactor(), 0.15); // default value
85 QCOMPARE(slice1.explodeDistanceFactor(), 0.15); // default value
85 QCOMPARE(slice1.explodeDistanceFactor(), 0.15); // default value
86 QCOMPARE(slice1.percentage(), 0.0);
86 QCOMPARE(slice1.percentage(), 0.0);
87 QCOMPARE(slice1.startAngle(), 0.0);
87 QCOMPARE(slice1.startAngle(), 0.0);
88 QCOMPARE(slice1.angleSpan(), 0.0);
88 QCOMPARE(slice1.angleSpan(), 0.0);
89
89
90 // value and label params
90 // value and label params
91 QPieSlice slice2("foobar", 1.0);
91 QPieSlice slice2("foobar", 1.0);
92 QCOMPARE(slice2.value(), 1.0);
92 QCOMPARE(slice2.value(), 1.0);
93 QCOMPARE(slice2.label(), QString("foobar"));
93 QCOMPARE(slice2.label(), QString("foobar"));
94 QVERIFY(!slice2.isLabelVisible());
94 QVERIFY(!slice2.isLabelVisible());
95 QVERIFY(!slice2.isExploded());
95 QVERIFY(!slice2.isExploded());
96 QCOMPARE(slice2.pen(), QPen());
96 QCOMPARE(slice2.pen(), QPen());
97 QCOMPARE(slice2.brush(), QBrush());
97 QCOMPARE(slice2.brush(), QBrush());
98 QCOMPARE(slice2.labelPen(), QPen());
98 QCOMPARE(slice2.labelBrush(), QBrush());
99 QCOMPARE(slice2.labelFont(), QFont());
99 QCOMPARE(slice2.labelFont(), QFont());
100 QCOMPARE(slice2.labelArmLengthFactor(), 0.15); // default value
100 QCOMPARE(slice2.labelArmLengthFactor(), 0.15); // default value
101 QCOMPARE(slice2.explodeDistanceFactor(), 0.15); // default value
101 QCOMPARE(slice2.explodeDistanceFactor(), 0.15); // default value
102 QCOMPARE(slice2.percentage(), 0.0);
102 QCOMPARE(slice2.percentage(), 0.0);
103 QCOMPARE(slice2.startAngle(), 0.0);
103 QCOMPARE(slice2.startAngle(), 0.0);
104 QCOMPARE(slice2.angleSpan(), 0.0);
104 QCOMPARE(slice2.angleSpan(), 0.0);
105 }
105 }
106
106
107 void tst_qpieslice::changedSignals()
107 void tst_qpieslice::changedSignals()
108 {
108 {
109 QPieSlice slice;
109 QPieSlice slice;
110
110
111 QSignalSpy valueSpy(&slice, SIGNAL(valueChanged()));
111 QSignalSpy valueSpy(&slice, SIGNAL(valueChanged()));
112 QSignalSpy labelSpy(&slice, SIGNAL(labelChanged()));
112 QSignalSpy labelSpy(&slice, SIGNAL(labelChanged()));
113 QSignalSpy explodedSpy(&slice, SIGNAL(explodedChanged()));
113 QSignalSpy explodedSpy(&slice, SIGNAL(explodedChanged()));
114 QSignalSpy penSpy(&slice, SIGNAL(penChanged()));
114 QSignalSpy penSpy(&slice, SIGNAL(penChanged()));
115 QSignalSpy brushSpy(&slice, SIGNAL(brushChanged()));
115 QSignalSpy brushSpy(&slice, SIGNAL(brushChanged()));
116 QSignalSpy labelPenSpy(&slice, SIGNAL(labelPenChanged()));
116 QSignalSpy labelBrushSpy(&slice, SIGNAL(labelBrushChanged()));
117 QSignalSpy labelFontSpy(&slice, SIGNAL(labelFontChanged()));
117 QSignalSpy labelFontSpy(&slice, SIGNAL(labelFontChanged()));
118 QSignalSpy labelArmLengthFactorSpy(&slice, SIGNAL(labelArmLengthFactorChanged()));
118 QSignalSpy labelArmLengthFactorSpy(&slice, SIGNAL(labelArmLengthFactorChanged()));
119 QSignalSpy explodeDistanceFactorSpy(&slice, SIGNAL(explodeDistanceFactorChanged()));
119 QSignalSpy explodeDistanceFactorSpy(&slice, SIGNAL(explodeDistanceFactorChanged()));
120
120
121 // percentageChanged(), startAngleChanged() and angleSpanChanged() signals tested at tst_qpieseries::calculatedValues()
121 // percentageChanged(), startAngleChanged() and angleSpanChanged() signals tested at tst_qpieseries::calculatedValues()
122
122
123 // set everything twice to see we do not get unnecessary signals
123 // set everything twice to see we do not get unnecessary signals
124 slice.setValue(1.0);
124 slice.setValue(1.0);
125 slice.setValue(-1.0);
125 slice.setValue(-1.0);
126 QCOMPARE(slice.value(), 1.0);
126 QCOMPARE(slice.value(), 1.0);
127 slice.setLabel("foobar");
127 slice.setLabel("foobar");
128 slice.setLabel("foobar");
128 slice.setLabel("foobar");
129 slice.setLabelVisible();
129 slice.setLabelVisible();
130 slice.setLabelVisible();
130 slice.setLabelVisible();
131 slice.setExploded();
131 slice.setExploded();
132 slice.setExploded();
132 slice.setExploded();
133 slice.setPen(QPen(Qt::red));
133 slice.setPen(QPen(Qt::red));
134 slice.setPen(QPen(Qt::red));
134 slice.setPen(QPen(Qt::red));
135 slice.setBrush(QBrush(Qt::red));
135 slice.setBrush(QBrush(Qt::red));
136 slice.setBrush(QBrush(Qt::red));
136 slice.setBrush(QBrush(Qt::red));
137 slice.setLabelPen(QPen(Qt::green));
137 slice.setLabelBrush(QBrush(Qt::green));
138 slice.setLabelPen(QPen(Qt::green));
138 slice.setLabelBrush(QBrush(Qt::green));
139 slice.setLabelFont(QFont("Tahoma"));
139 slice.setLabelFont(QFont("Tahoma"));
140 slice.setLabelFont(QFont("Tahoma"));
140 slice.setLabelFont(QFont("Tahoma"));
141 slice.setLabelArmLengthFactor(0.1);
141 slice.setLabelArmLengthFactor(0.1);
142 slice.setLabelArmLengthFactor(0.1);
142 slice.setLabelArmLengthFactor(0.1);
143 slice.setExplodeDistanceFactor(0.1);
143 slice.setExplodeDistanceFactor(0.1);
144 slice.setExplodeDistanceFactor(0.1);
144 slice.setExplodeDistanceFactor(0.1);
145
145
146 TRY_COMPARE(valueSpy.count(), 1);
146 TRY_COMPARE(valueSpy.count(), 1);
147 TRY_COMPARE(labelSpy.count(), 1);
147 TRY_COMPARE(labelSpy.count(), 1);
148 TRY_COMPARE(explodedSpy.count(), 1);
148 TRY_COMPARE(explodedSpy.count(), 1);
149 TRY_COMPARE(penSpy.count(), 1);
149 TRY_COMPARE(penSpy.count(), 1);
150 TRY_COMPARE(brushSpy.count(), 1);
150 TRY_COMPARE(brushSpy.count(), 1);
151 TRY_COMPARE(labelPenSpy.count(), 1);
151 TRY_COMPARE(labelBrushSpy.count(), 1);
152 TRY_COMPARE(labelFontSpy.count(), 1);
152 TRY_COMPARE(labelFontSpy.count(), 1);
153 TRY_COMPARE(labelArmLengthFactorSpy.count(), 1);
153 TRY_COMPARE(labelArmLengthFactorSpy.count(), 1);
154 TRY_COMPARE(explodeDistanceFactorSpy.count(), 1);
154 TRY_COMPARE(explodeDistanceFactorSpy.count(), 1);
155 }
155 }
156
156
157 void tst_qpieslice::customize()
157 void tst_qpieslice::customize()
158 {
158 {
159 // create a pie series
159 // create a pie series
160 QPieSeries *series = new QPieSeries();
160 QPieSeries *series = new QPieSeries();
161 QPieSlice *s1 = series->append("slice 1", 1);
161 QPieSlice *s1 = series->append("slice 1", 1);
162 QPieSlice *s2 = series->append("slice 2", 2);
162 QPieSlice *s2 = series->append("slice 2", 2);
163 series->append("slice 3", 3);
163 series->append("slice 3", 3);
164
164
165 // customize a slice
165 // customize a slice
166 QPen p1(Qt::red);
166 QPen p1(Qt::red);
167 s1->setPen(p1);
167 s1->setPen(p1);
168 QBrush b1(Qt::red);
168 QBrush b1(Qt::red);
169 s1->setBrush(b1);
169 s1->setBrush(b1);
170 s1->setLabelPen(p1);
170 s1->setLabelBrush(b1);
171 QFont f1("Consolas");
171 QFont f1("Consolas");
172 s1->setLabelFont(f1);
172 s1->setLabelFont(f1);
173
173
174 // add series to the chart
174 // add series to the chart
175 QChartView view(new QChart());
175 QChartView view(new QChart());
176 view.resize(200, 200);
176 view.resize(200, 200);
177 view.chart()->addSeries(series);
177 view.chart()->addSeries(series);
178 view.show();
178 view.show();
179 QTest::qWaitForWindowShown(&view);
179 QTest::qWaitForWindowShown(&view);
180 //QTest::qWait(1000);
180 //QTest::qWait(1000);
181
181
182 // check that customizations persist
182 // check that customizations persist
183 QCOMPARE(s1->pen(), p1);
183 QCOMPARE(s1->pen(), p1);
184 QCOMPARE(s1->brush(), b1);
184 QCOMPARE(s1->brush(), b1);
185 QCOMPARE(s1->labelPen(), p1);
185 QCOMPARE(s1->labelBrush(), b1);
186 QCOMPARE(s1->labelFont(), f1);
186 QCOMPARE(s1->labelFont(), f1);
187
187
188 // remove a slice
188 // remove a slice
189 series->remove(s2);
189 series->remove(s2);
190 QCOMPARE(s1->pen(), p1);
190 QCOMPARE(s1->pen(), p1);
191 QCOMPARE(s1->brush(), b1);
191 QCOMPARE(s1->brush(), b1);
192 QCOMPARE(s1->labelPen(), p1);
192 QCOMPARE(s1->labelBrush(), b1);
193 QCOMPARE(s1->labelFont(), f1);
193 QCOMPARE(s1->labelFont(), f1);
194
194
195 // add a slice
195 // add a slice
196 series->append("slice 4", 4);
196 series->append("slice 4", 4);
197 QCOMPARE(s1->pen(), p1);
197 QCOMPARE(s1->pen(), p1);
198 QCOMPARE(s1->brush(), b1);
198 QCOMPARE(s1->brush(), b1);
199 QCOMPARE(s1->labelPen(), p1);
199 QCOMPARE(s1->labelBrush(), b1);
200 QCOMPARE(s1->labelFont(), f1);
200 QCOMPARE(s1->labelFont(), f1);
201
201
202 // insert a slice
202 // insert a slice
203 series->insert(0, new QPieSlice("slice 5", 5));
203 series->insert(0, new QPieSlice("slice 5", 5));
204 QCOMPARE(s1->pen(), p1);
204 QCOMPARE(s1->pen(), p1);
205 QCOMPARE(s1->brush(), b1);
205 QCOMPARE(s1->brush(), b1);
206 QCOMPARE(s1->labelPen(), p1);
206 QCOMPARE(s1->labelBrush(), b1);
207 QCOMPARE(s1->labelFont(), f1);
207 QCOMPARE(s1->labelFont(), f1);
208
208
209 // change theme
209 // change theme
210 // theme will overwrite customizations
210 // theme will overwrite customizations
211 view.chart()->setTheme(QChart::ChartThemeHighContrast);
211 view.chart()->setTheme(QChart::ChartThemeHighContrast);
212 QVERIFY(s1->pen() != p1);
212 QVERIFY(s1->pen() != p1);
213 QVERIFY(s1->brush() != b1);
213 QVERIFY(s1->brush() != b1);
214 QVERIFY(s1->labelPen() != p1);
214 QVERIFY(s1->labelBrush() != b1);
215 QVERIFY(s1->labelFont() != f1);
215 QVERIFY(s1->labelFont() != f1);
216 }
216 }
217
217
218 void tst_qpieslice::mouseClick()
218 void tst_qpieslice::mouseClick()
219 {
219 {
220 // create a pie series
220 // create a pie series
221 QPieSeries *series = new QPieSeries();
221 QPieSeries *series = new QPieSeries();
222 series->setPieSize(1.0);
222 series->setPieSize(1.0);
223 QPieSlice *s1 = series->append("slice 1", 1);
223 QPieSlice *s1 = series->append("slice 1", 1);
224 QPieSlice *s2 = series->append("slice 2", 2);
224 QPieSlice *s2 = series->append("slice 2", 2);
225 QPieSlice *s3 = series->append("slice 3", 3);
225 QPieSlice *s3 = series->append("slice 3", 3);
226 QSignalSpy clickSpy1(s1, SIGNAL(clicked()));
226 QSignalSpy clickSpy1(s1, SIGNAL(clicked()));
227 QSignalSpy clickSpy2(s2, SIGNAL(clicked()));
227 QSignalSpy clickSpy2(s2, SIGNAL(clicked()));
228 QSignalSpy clickSpy3(s3, SIGNAL(clicked()));
228 QSignalSpy clickSpy3(s3, SIGNAL(clicked()));
229
229
230 // add series to the chart
230 // add series to the chart
231 QChartView view(new QChart());
231 QChartView view(new QChart());
232 view.chart()->legend()->setVisible(false);
232 view.chart()->legend()->setVisible(false);
233 view.resize(200, 200);
233 view.resize(200, 200);
234 view.chart()->addSeries(series);
234 view.chart()->addSeries(series);
235 view.show();
235 view.show();
236 QTest::qWaitForWindowShown(&view);
236 QTest::qWaitForWindowShown(&view);
237
237
238 // simulate clicks
238 // simulate clicks
239 // pie rectangle: QRectF(60,60 121x121)
239 // pie rectangle: QRectF(60,60 121x121)
240 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1
240 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1
241 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(146, 136)); // inside slice 2
241 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(146, 136)); // inside slice 2
242 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(91, 119)); // inside slice 3
242 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(91, 119)); // inside slice 3
243 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(70, 70)); // inside pie rectangle but not inside a slice
243 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(70, 70)); // inside pie rectangle but not inside a slice
244 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(170, 170)); // inside pie rectangle but not inside a slice
244 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(170, 170)); // inside pie rectangle but not inside a slice
245 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
245 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
246 QCOMPARE(clickSpy1.count(), 1);
246 QCOMPARE(clickSpy1.count(), 1);
247 QCOMPARE(clickSpy2.count(), 1);
247 QCOMPARE(clickSpy2.count(), 1);
248 QCOMPARE(clickSpy3.count(), 1);
248 QCOMPARE(clickSpy3.count(), 1);
249 }
249 }
250
250
251 void tst_qpieslice::mouseHover()
251 void tst_qpieslice::mouseHover()
252 {
252 {
253 // create a pie series
253 // create a pie series
254 QPieSeries *series = new QPieSeries();
254 QPieSeries *series = new QPieSeries();
255 series->setPieSize(1.0);
255 series->setPieSize(1.0);
256 QPieSlice *s1 = series->append("slice 1", 1);
256 QPieSlice *s1 = series->append("slice 1", 1);
257 series->append("slice 2", 2);
257 series->append("slice 2", 2);
258 series->append("slice 3", 3);
258 series->append("slice 3", 3);
259
259
260 // add series to the chart
260 // add series to the chart
261 QChartView view(new QChart());
261 QChartView view(new QChart());
262 view.chart()->legend()->setVisible(false);
262 view.chart()->legend()->setVisible(false);
263 view.resize(200, 200);
263 view.resize(200, 200);
264 view.chart()->addSeries(series);
264 view.chart()->addSeries(series);
265 view.show();
265 view.show();
266 QTest::qWaitForWindowShown(&view);
266 QTest::qWaitForWindowShown(&view);
267
267
268 // first move to right top corner
268 // first move to right top corner
269 QTest::mouseMove(view.viewport(), QPoint(200, 0));
269 QTest::mouseMove(view.viewport(), QPoint(200, 0));
270 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
270 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
271
271
272 // move inside slice rectangle but NOT the actual slice
272 // move inside slice rectangle but NOT the actual slice
273 // pie rectangle: QRectF(60,60 121x121)
273 // pie rectangle: QRectF(60,60 121x121)
274 QSignalSpy hoverSpy(s1, SIGNAL(hovered(bool)));
274 QSignalSpy hoverSpy(s1, SIGNAL(hovered(bool)));
275 QTest::mouseMove(view.viewport(), QPoint(170, 70));
275 QTest::mouseMove(view.viewport(), QPoint(170, 70));
276 TRY_COMPARE(hoverSpy.count(), 0);
276 TRY_COMPARE(hoverSpy.count(), 0);
277
277
278 // move inside the slice
278 // move inside the slice
279 QTest::mouseMove(view.viewport(), QPoint(139, 85));
279 QTest::mouseMove(view.viewport(), QPoint(139, 85));
280 TRY_COMPARE(hoverSpy.count(), 1);
280 TRY_COMPARE(hoverSpy.count(), 1);
281 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(0)), true);
281 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(0)), true);
282
282
283 // move outside the slice
283 // move outside the slice
284 QTest::mouseMove(view.viewport(), QPoint(200, 0));
284 QTest::mouseMove(view.viewport(), QPoint(200, 0));
285 TRY_COMPARE(hoverSpy.count(), 2);
285 TRY_COMPARE(hoverSpy.count(), 2);
286 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(0)), false);
286 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(0)), false);
287 }
287 }
288
288
289 QTEST_MAIN(tst_qpieslice)
289 QTEST_MAIN(tst_qpieslice)
290
290
291 #include "tst_qpieslice.moc"
291 #include "tst_qpieslice.moc"
292
292
General Comments 0
You need to be logged in to leave comments. Login now