##// END OF EJS Templates
Removed unnecessary signals from QPieSlice
Tero Ahola -
r1494:0e4d11fde6b8
parent child
Show More
@@ -1,216 +1,222
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 QPieSeriesPrivate *p = QPieSeriesPrivate::fromSeries(series);
41 QPieSeriesPrivate *p = QPieSeriesPrivate::fromSeries(series);
42 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
42 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
43 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
43 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
44 connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
44 connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
45 connect(p, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout()));
45 connect(p, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout()));
46 connect(p, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout()));
46 connect(p, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout()));
47 connect(p, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout()));
47 connect(p, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout()));
48 connect(p, SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout()));
48 connect(p, SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout()));
49
49
50 // Note: the following does not affect as long as the item does not have anything to paint
50 // Note: the following does not affect as long as the item does not have anything to paint
51 setZValue(ChartPresenter::PieSeriesZValue);
51 setZValue(ChartPresenter::PieSeriesZValue);
52
52
53 // Note: will not create slice items until we have a proper rectangle to draw on.
53 // Note: will not create slice items until we have a proper rectangle to draw on.
54 }
54 }
55
55
56 PieChartItem::~PieChartItem()
56 PieChartItem::~PieChartItem()
57 {
57 {
58 // slices deleted automatically through QGraphicsItem
58 // slices deleted automatically through QGraphicsItem
59 }
59 }
60
60
61 void PieChartItem::handleGeometryChanged(const QRectF& rect)
61 void PieChartItem::handleGeometryChanged(const QRectF& rect)
62 {
62 {
63 prepareGeometryChange();
63 prepareGeometryChange();
64 m_rect = rect;
64 m_rect = rect;
65 updateLayout();
65 updateLayout();
66
66
67 // This is for delayed initialization of the slice items during startup.
67 // This is for delayed initialization of the slice items during startup.
68 // It ensures that startup animation originates from the correct position.
68 // It ensures that startup animation originates from the correct position.
69 if (m_sliceItems.isEmpty())
69 if (m_sliceItems.isEmpty())
70 handleSlicesAdded(m_series->slices());
70 handleSlicesAdded(m_series->slices());
71 }
71 }
72
72
73 void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
73 void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
74 {
74 {
75 Q_UNUSED(minX);
75 Q_UNUSED(minX);
76 Q_UNUSED(maxX);
76 Q_UNUSED(maxX);
77 Q_UNUSED(minY);
77 Q_UNUSED(minY);
78 Q_UNUSED(maxY);
78 Q_UNUSED(maxY);
79 // does not apply to pie
79 // does not apply to pie
80 }
80 }
81
81
82 void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount)
82 void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount)
83 {
83 {
84 Q_UNUSED(min);
84 Q_UNUSED(min);
85 Q_UNUSED(max);
85 Q_UNUSED(max);
86 Q_UNUSED(tickXCount);
86 Q_UNUSED(tickXCount);
87 // does not apply to pie
87 // does not apply to pie
88 }
88 }
89
89
90 void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount)
90 void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount)
91 {
91 {
92 Q_UNUSED(min);
92 Q_UNUSED(min);
93 Q_UNUSED(max);
93 Q_UNUSED(max);
94 Q_UNUSED(tickYCount);
94 Q_UNUSED(tickYCount);
95 // does not apply to pie
95 // does not apply to pie
96 }
96 }
97
97
98 void PieChartItem::updateLayout()
98 void PieChartItem::updateLayout()
99 {
99 {
100 // find pie center coordinates
100 // find pie center coordinates
101 m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->horizontalPosition()));
101 m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->horizontalPosition()));
102 m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->verticalPosition()));
102 m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->verticalPosition()));
103
103
104 // find maximum radius for pie
104 // find maximum radius for pie
105 m_pieRadius = m_rect.height() / 2;
105 m_pieRadius = m_rect.height() / 2;
106 if (m_rect.width() < m_rect.height())
106 if (m_rect.width() < m_rect.height())
107 m_pieRadius = m_rect.width() / 2;
107 m_pieRadius = m_rect.width() / 2;
108
108
109 // apply size factor
109 // apply size factor
110 m_pieRadius *= m_series->pieSize();
110 m_pieRadius *= m_series->pieSize();
111
111
112 // set layouts for existing slice items
112 // set layouts for existing slice items
113 foreach (QPieSlice* slice, m_series->slices()) {
113 foreach (QPieSlice* slice, m_series->slices()) {
114 PieSliceItem *sliceItem = m_sliceItems.value(slice);
114 PieSliceItem *sliceItem = m_sliceItems.value(slice);
115 if (sliceItem) {
115 if (sliceItem) {
116 PieSliceData sliceData = updateSliceGeometry(slice);
116 PieSliceData sliceData = updateSliceGeometry(slice);
117 if (animator())
117 if (animator())
118 animator()->updateAnimation(this, sliceItem, sliceData);
118 animator()->updateAnimation(this, sliceItem, sliceData);
119 else
119 else
120 sliceItem->setLayout(sliceData);
120 sliceItem->setLayout(sliceData);
121 }
121 }
122 }
122 }
123
123
124 update();
124 update();
125 }
125 }
126
126
127 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
127 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
128 {
128 {
129 // delay creating slice items until there is a proper rectangle
129 // delay creating slice items until there is a proper rectangle
130 if (!m_rect.isValid() && m_sliceItems.isEmpty())
130 if (!m_rect.isValid() && m_sliceItems.isEmpty())
131 return;
131 return;
132
132
133 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
133 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
134
134
135 bool startupAnimation = m_sliceItems.isEmpty();
135 bool startupAnimation = m_sliceItems.isEmpty();
136
136
137 foreach (QPieSlice *slice, slices) {
137 foreach (QPieSlice *slice, slices) {
138 PieSliceItem* sliceItem = new PieSliceItem(this);
138 PieSliceItem* sliceItem = new PieSliceItem(this);
139 m_sliceItems.insert(slice, sliceItem);
139 m_sliceItems.insert(slice, sliceItem);
140
140
141 // Note: do need to connect to slice valueChanged() etc.
141 // Note: no need to connect to slice valueChanged() etc.
142 // This is handled through calculatedDataChanged signal.
142 // This is handled through calculatedDataChanged signal.
143 connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged()));
143 connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged()));
144 connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged()));
144 connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged()));
145 connect(slice, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged()));
146 connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged()));
145 connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged()));
147 connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged()));
146 connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged()));
148 connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged()));
147 connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged()));
149 connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged()));
148 connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged()));
150 connect(slice, SIGNAL(labelPositionChanged()), this, SLOT(handleSliceChanged()));
149
151 connect(slice, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged()));
150 QPieSlicePrivate *p = QPieSlicePrivate::fromSlice(slice);
152 connect(slice, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged()));
151 connect(p, SIGNAL(labelPositionChanged()), this, SLOT(handleSliceChanged()));
152 connect(p, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged()));
153 connect(p, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged()));
154 connect(p, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged()));
153
155
154 connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked()));
156 connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked()));
155 connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool)));
157 connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool)));
156
158
157 PieSliceData sliceData = updateSliceGeometry(slice);
159 PieSliceData sliceData = updateSliceGeometry(slice);
158 if (animator())
160 if (animator())
159 animator()->addAnimation(this, sliceItem, sliceData, startupAnimation);
161 animator()->addAnimation(this, sliceItem, sliceData, startupAnimation);
160 else
162 else
161 sliceItem->setLayout(sliceData);
163 sliceItem->setLayout(sliceData);
162 }
164 }
163 }
165 }
164
166
165 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
167 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
166 {
168 {
167 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
169 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
168
170
169 foreach (QPieSlice *slice, slices) {
171 foreach (QPieSlice *slice, slices) {
170
172
171 PieSliceItem *sliceItem = m_sliceItems.value(slice);
173 PieSliceItem *sliceItem = m_sliceItems.value(slice);
172
174
173 // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created
175 // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created
174 if (!sliceItem)
176 if (!sliceItem)
175 continue;
177 continue;
176
178
177 m_sliceItems.remove(slice);
179 m_sliceItems.remove(slice);
178
180
179 if (animator())
181 if (animator())
180 animator()->removeAnimation(this, sliceItem); // animator deletes the PieSliceItem
182 animator()->removeAnimation(this, sliceItem); // animator deletes the PieSliceItem
181 else
183 else
182 delete sliceItem;
184 delete sliceItem;
183 }
185 }
184 }
186 }
185
187
186 void PieChartItem::handleSliceChanged()
188 void PieChartItem::handleSliceChanged()
187 {
189 {
188 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
190 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
191 if (!slice) {
192 QPieSlicePrivate* slicep = qobject_cast<QPieSlicePrivate *>(sender());
193 slice = slicep->q_ptr;
194 }
189 Q_ASSERT(m_sliceItems.contains(slice));
195 Q_ASSERT(m_sliceItems.contains(slice));
190
196
191 PieSliceItem *sliceItem = m_sliceItems.value(slice);
197 PieSliceItem *sliceItem = m_sliceItems.value(slice);
192 PieSliceData sliceData = updateSliceGeometry(slice);
198 PieSliceData sliceData = updateSliceGeometry(slice);
193 if (animator())
199 if (animator())
194 animator()->updateAnimation(this, sliceItem, sliceData);
200 animator()->updateAnimation(this, sliceItem, sliceData);
195 else
201 else
196 sliceItem->setLayout(sliceData);
202 sliceItem->setLayout(sliceData);
197
203
198 update();
204 update();
199 }
205 }
200
206
201 void PieChartItem::handleSeriesVisibleChanged()
207 void PieChartItem::handleSeriesVisibleChanged()
202 {
208 {
203 setVisible(m_series->isVisible());
209 setVisible(m_series->isVisible());
204 }
210 }
205
211
206 PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice)
212 PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice)
207 {
213 {
208 PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data;
214 PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data;
209 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
215 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
210 sliceData.m_radius = m_pieRadius;
216 sliceData.m_radius = m_pieRadius;
211 return sliceData;
217 return sliceData;
212 }
218 }
213
219
214 #include "moc_piechartitem_p.cpp"
220 #include "moc_piechartitem_p.cpp"
215
221
216 QTCOMMERCIALCHART_END_NAMESPACE
222 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,813 +1,769
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 \qmlclass PieSlice QPieSlice
42 \qmlclass PieSlice QPieSlice
43 PieSlice defines the properties of a single slice in a PieSeries. The element should be used
43 PieSlice defines the properties of a single slice in a PieSeries. The element should be used
44 as a child for a PieSeries. For example:
44 as a child for a PieSeries. For example:
45 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
45 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
46
46
47 An alternative (dynamic) method for adding slices to a PieSeries is using PieSeries.append
47 An alternative (dynamic) method for adding slices to a PieSeries is using PieSeries.append
48 method.
48 method.
49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 4
49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 4
50
50
51 In that case you may want to use PieSeries.at or PieSeries.find to access the properties of
51 In that case you may want to use PieSeries.at or PieSeries.find to access the properties of
52 an individual PieSlice instance.
52 an individual PieSlice instance.
53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 5
53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 5
54 \sa PieSeries
54 \sa PieSeries
55 */
55 */
56
56
57 /*!
57 /*!
58 \enum QPieSlice::LabelPosition
58 \enum QPieSlice::LabelPosition
59
59
60 This enum describes the position of the slice label.
60 This enum describes the position of the slice label.
61
61
62 \value LabelOutside Label is outside the slice with an arm.
62 \value LabelOutside Label is outside the slice with an arm.
63 \value LabelInside Label is centered inside the slice.
63 \value LabelInside Label is centered inside the slice.
64
64
65 */
65 */
66
66
67 /*!
67 /*!
68 \property QPieSlice::label
68 \property QPieSlice::label
69 Label of the slice.
69 Label of the slice.
70 \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor
70 \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor
71 */
71 */
72 /*!
72 /*!
73 \qmlproperty string PieSlice::label
73 \qmlproperty string PieSlice::label
74 Label (text) of the slice.
74 Label (text) of the slice.
75 */
75 */
76
76
77 /*!
77 /*!
78 \fn void QPieSlice::labelChanged()
78 \fn void QPieSlice::labelChanged()
79 This signal emitted when the slice label has been changed.
79 This signal emitted when the slice label has been changed.
80 \sa label
80 \sa label
81 */
81 */
82 /*!
82 /*!
83 \qmlsignal PieSlice::labelChanged()
83 \qmlsignal PieSlice::labelChanged()
84 This signal emitted when the slice label has been changed.
84 This signal emitted when the slice label has been changed.
85 \sa label
85 \sa label
86 */
86 */
87
87
88 /*!
88 /*!
89 \property QPieSlice::value
89 \property QPieSlice::value
90 Value of the slice.
90 Value of the slice.
91 Note that if users sets a negative value it is converted to a positive value.
91 Note that if users sets a negative value it is converted to a positive value.
92 \sa percentage(), QPieSeries::sum()
92 \sa percentage(), QPieSeries::sum()
93 */
93 */
94 /*!
94 /*!
95 \qmlproperty real PieSlice::value
95 \qmlproperty real PieSlice::value
96 Value of the slice. Note that if users sets a negative value it is converted to a positive value.
96 Value of the slice. Note that if users sets a negative value it is converted to a positive value.
97 */
97 */
98
98
99 /*!
99 /*!
100 \fn void QPieSlice::valueChanged()
100 \fn void QPieSlice::valueChanged()
101 This signal is emitted when the slice value changes.
101 This signal is emitted when the slice value changes.
102 \sa value
102 \sa value
103 */
103 */
104 /*!
104 /*!
105 \qmlsignal PieSlice::valueChanged()
105 \qmlsignal PieSlice::valueChanged()
106 This signal is emitted when the slice value changes.
106 This signal is emitted when the slice value changes.
107 \sa value
107 \sa value
108 */
108 */
109
109
110 /*!
110 /*!
111 \property QPieSlice::labelVisible
111 \property QPieSlice::labelVisible
112 Defines the visibility of slice label. By default the label is not visible.
112 Defines the visibility of slice label. By default the label is not visible.
113 \sa label, labelBrush, labelFont, labelArmLengthFactor
113 \sa label, labelBrush, labelFont, labelArmLengthFactor
114 */
114 */
115 /*!
115 /*!
116 \qmlproperty bool PieSlice::labelVisible
116 \qmlproperty bool PieSlice::labelVisible
117 Defines the visibility of slice label. By default the label is not visible.
117 Defines the visibility of slice label. By default the label is not visible.
118 */
118 */
119
119
120 /*!
120 /*!
121 \fn void QPieSlice::labelVisibleChanged()
121 \fn void QPieSlice::labelVisibleChanged()
122 This signal emitted when visibility of the slice label has changed.
122 This signal emitted when visibility of the slice label has changed.
123 \sa labelVisible
123 \sa labelVisible
124 */
124 */
125 /*!
125 /*!
126 \qmlsignal PieSlice::labelVisibleChanged()
126 \qmlsignal PieSlice::labelVisibleChanged()
127 This signal emitted when visibility of the slice label has changed.
127 This signal emitted when visibility of the slice label has changed.
128 \sa labelVisible
128 \sa labelVisible
129 */
129 */
130
130
131 /*!
131 /*!
132 \property QPieSlice::exploded
132 \property QPieSlice::exploded
133 If set to true the slice is "exploded" away from the pie.
133 If set to true the slice is "exploded" away from the pie.
134 \sa explodeDistanceFactor
134 \sa explodeDistanceFactor
135 */
135 */
136 /*!
136 /*!
137 \qmlproperty bool PieSlice::exploded
137 \qmlproperty bool PieSlice::exploded
138 If set to true the slice is "exploded" away from the pie.
138 If set to true the slice is "exploded" away from the pie.
139 \sa explodeDistanceFactor
139 \sa explodeDistanceFactor
140 */
140 */
141
141
142 /*!
142 /*!
143 \fn void QPieSlice::explodedChanged()
144 This signal is emitted the the slice has been exploded from the pie or is returned back to the pie.
145 \sa exploded
146 */
147 /*!
148 \qmlsignal PieSlice::explodedChanged()
149 This signal is emitted the the slice has been exploded from the pie or is returned back to the pie.
150 \sa exploded
151 */
152
153 /*!
154 \property QPieSlice::pen
143 \property QPieSlice::pen
155 Pen used to draw the slice border.
144 Pen used to draw the slice border.
156 */
145 */
157
146
158 /*!
147 /*!
159 \fn void QPieSlice::penChanged()
148 \fn void QPieSlice::penChanged()
160 This signal is emitted when the pen of the slice has changed.
149 This signal is emitted when the pen of the slice has changed.
161 \sa pen
150 \sa pen
162 */
151 */
163
152
164 /*!
153 /*!
165 \property QPieSlice::borderColor
154 \property QPieSlice::borderColor
166 Color used to draw the slice border.
155 Color used to draw the slice border.
167 This is a convenience property for modifying the slice pen.
156 This is a convenience property for modifying the slice pen.
168 \sa pen, borderWidth
157 \sa pen, borderWidth
169 */
158 */
170 /*!
159 /*!
171 \qmlproperty color PieSlice::borderColor
160 \qmlproperty color PieSlice::borderColor
172 Color used to draw the slice border (pen color).
161 Color used to draw the slice border (pen color).
173 \sa borderWidth
162 \sa borderWidth
174 */
163 */
175
164
176 /*!
165 /*!
177 \fn void QPieSlice::borderColorChanged()
166 \fn void QPieSlice::borderColorChanged()
178 This signal is emitted when slice border color changes.
167 This signal is emitted when slice border color changes.
179 \sa pen, borderColor
168 \sa pen, borderColor
180 */
169 */
181 /*!
170 /*!
182 \qmlsignal PieSlice::borderColorChanged()
171 \qmlsignal PieSlice::borderColorChanged()
183 This signal is emitted when slice border color changes.
172 This signal is emitted when slice border color changes.
184 \sa borderColor
173 \sa borderColor
185 */
174 */
186
175
187 /*!
176 /*!
188 \property QPieSlice::borderWidth
177 \property QPieSlice::borderWidth
189 Width of the slice border.
178 Width of the slice border.
190 This is a convenience property for modifying the slice pen.
179 This is a convenience property for modifying the slice pen.
191 \sa pen, borderColor
180 \sa pen, borderColor
192 */
181 */
193 /*!
182 /*!
194 \qmlproperty int PieSlice::borderWidth
183 \qmlproperty int PieSlice::borderWidth
195 Width of the slice border.
184 Width of the slice border.
196 This is a convenience property for modifying the slice pen.
185 This is a convenience property for modifying the slice pen.
197 \sa borderColor
186 \sa borderColor
198 */
187 */
199
188
200 /*!
189 /*!
201 \fn void QPieSlice::borderWidthChanged()
190 \fn void QPieSlice::borderWidthChanged()
202 This signal is emitted when slice border width changes.
191 This signal is emitted when slice border width changes.
203 \sa pen, borderWidth
192 \sa pen, borderWidth
204 */
193 */
205 /*!
194 /*!
206 \qmlsignal PieSlice::borderWidthChanged()
195 \qmlsignal PieSlice::borderWidthChanged()
207 This signal is emitted when slice border width changes.
196 This signal is emitted when slice border width changes.
208 \sa borderWidth
197 \sa borderWidth
209 */
198 */
210
199
211 /*!
200 /*!
212 \property QPieSlice::brush
201 \property QPieSlice::brush
213 Brush used to draw the slice.
202 Brush used to draw the slice.
214 */
203 */
215
204
216 /*!
205 /*!
217 \fn void QPieSlice::brushChanged()
206 \fn void QPieSlice::brushChanged()
218 This signal is emitted when the brush of the slice has changed.
207 This signal is emitted when the brush of the slice has changed.
219 \sa brush
208 \sa brush
220 */
209 */
221
210
222 /*!
211 /*!
223 \property QPieSlice::color
212 \property QPieSlice::color
224 Fill (brush) color of the slice.
213 Fill (brush) color of the slice.
225 This is a convenience property for modifying the slice brush.
214 This is a convenience property for modifying the slice brush.
226 \sa brush
215 \sa brush
227 */
216 */
228 /*!
217 /*!
229 \qmlproperty color PieSlice::color
218 \qmlproperty color PieSlice::color
230 Fill (brush) color of the slice.
219 Fill (brush) color of the slice.
231 */
220 */
232
221
233 /*!
222 /*!
234 \fn void QPieSlice::colorChanged()
223 \fn void QPieSlice::colorChanged()
235 This signal is emitted when slice color changes.
224 This signal is emitted when slice color changes.
236 \sa brush
225 \sa brush
237 */
226 */
238 /*!
227 /*!
239 \qmlsignal PieSlice::colorChanged()
228 \qmlsignal PieSlice::colorChanged()
240 This signal is emitted when slice color changes.
229 This signal is emitted when slice color changes.
241 */
230 */
242
231
243 /*!
232 /*!
244 \property QPieSlice::labelBrush
233 \property QPieSlice::labelBrush
245 Brush used to draw label and label arm of the slice.
234 Brush used to draw label and label arm of the slice.
246 \sa label, labelVisible, labelFont, labelArmLengthFactor
235 \sa label, labelVisible, labelFont, labelArmLengthFactor
247 */
236 */
248
237
249 /*!
238 /*!
250 \fn void QPieSlice::labelBrushChanged()
239 \fn void QPieSlice::labelBrushChanged()
251 This signal is emitted when the label pen of the slice has changed.
240 This signal is emitted when the label pen of the slice has changed.
252 \sa labelBrush
241 \sa labelBrush
253 */
242 */
254
243
255 /*!
244 /*!
256 \property QPieSlice::labelColor
245 \property QPieSlice::labelColor
257 Color used to draw the slice label.
246 Color used to draw the slice label.
258 This is a convenience property for modifying the slice label brush.
247 This is a convenience property for modifying the slice label brush.
259 \sa labelBrush
248 \sa labelBrush
260 */
249 */
261 /*!
250 /*!
262 \qmlproperty color PieSlice::labelColor
251 \qmlproperty color PieSlice::labelColor
263 Color used to draw the slice label.
252 Color used to draw the slice label.
264 */
253 */
265
254
266 /*!
255 /*!
267 \fn void QPieSlice::labelColorChanged()
256 \fn void QPieSlice::labelColorChanged()
268 This signal is emitted when slice label color changes.
257 This signal is emitted when slice label color changes.
269 \sa labelColor
258 \sa labelColor
270 */
259 */
271 /*!
260 /*!
272 \qmlsignal PieSlice::labelColorChanged()
261 \qmlsignal PieSlice::labelColorChanged()
273 This signal is emitted when slice label color changes.
262 This signal is emitted when slice label color changes.
274 \sa labelColor
263 \sa labelColor
275 */
264 */
276
265
277 /*!
266 /*!
278 \property QPieSlice::labelFont
267 \property QPieSlice::labelFont
279 Font used for drawing label text.
268 Font used for drawing label text.
280 \sa label, labelVisible, labelArmLengthFactor
269 \sa label, labelVisible, labelArmLengthFactor
281 */
270 */
282
271
283 /*!
272 /*!
284 \fn void QPieSlice::labelFontChanged()
273 \fn void QPieSlice::labelFontChanged()
285 This signal is emitted when the label font of the slice has changed.
274 This signal is emitted when the label font of the slice has changed.
286 \sa labelFont
275 \sa labelFont
287 */
276 */
288
277
289 /*!
278 /*!
290 \property QPieSlice::labelPosition
279 \property QPieSlice::labelPosition
291 Position of the slice label.
280 Position of the slice label.
292 \sa label, labelVisible
281 \sa label, labelVisible
293 */
282 */
294 /*!
283 /*!
295 \qmlproperty LabelPosition PieSlice::labelPosition
284 \qmlproperty LabelPosition PieSlice::labelPosition
296 Position of the slice label. One of PieSlice.LabelOutside or PieSlice.LabelInside.
285 Position of the slice label. One of PieSlice.LabelOutside or PieSlice.LabelInside.
297 \sa labelVisible
286 \sa labelVisible
298 */
287 */
299
288
300 /*!
289 /*!
301 \fn void QPieSlice::labelPositionChanged()
302 This signal is emitted when the label position of the slice has changed.
303 \sa labelPosition
304 */
305 /*!
306 \qmlsignal PieSlice::labelPositionChanged()
307 This signal is emitted when the label position of the slice has changed.
308 \sa labelPosition
309 */
310
311 /*!
312 \property QPieSlice::labelArmLengthFactor
290 \property QPieSlice::labelArmLengthFactor
313 Defines the length of the label arm.
291 Defines the length of the label arm.
314 The factor is relative to pie radius. For example:
292 The factor is relative to pie radius. For example:
315 1.0 means the length is the same as the radius.
293 1.0 means the length is the same as the radius.
316 0.5 means the length is half of the radius.
294 0.5 means the length is half of the radius.
317 By default the arm length is 0.15
295 By default the arm length is 0.15
318 \sa label, labelVisible, labelBrush, labelFont
296 \sa label, labelVisible, labelBrush, labelFont
319 */
297 */
320 /*!
298 /*!
321 \qmlproperty real PieSlice::labelArmLengthFactor
299 \qmlproperty real PieSlice::labelArmLengthFactor
322 Defines the length of the label arm.
300 Defines the length of the label arm.
323 The factor is relative to pie radius. For example:
301 The factor is relative to pie radius. For example:
324 1.0 means the length is the same as the radius.
302 1.0 means the length is the same as the radius.
325 0.5 means the length is half of the radius.
303 0.5 means the length is half of the radius.
326 By default the arm length is 0.15
304 By default the arm length is 0.15
327 \sa labelVisible
305 \sa labelVisible
328 */
306 */
329
307
330 /*!
308 /*!
331 \fn void QPieSlice::labelArmLengthFactorChanged()
332 This signal is emitted when the label arm factor of the slice has changed.
333 \sa labelArmLengthFactor
334 */
335 /*!
336 \qmlsignal PieSlice::labelArmLengthFactorChanged()
337 This signal is emitted when the label arm factor of the slice has changed.
338 \sa labelArmLengthFactor
339 */
340
341 /*!
342 \property QPieSlice::explodeDistanceFactor
309 \property QPieSlice::explodeDistanceFactor
343 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
310 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
344 The factor is relative to pie radius. For example:
311 The factor is relative to pie radius. For example:
345 1.0 means the distance is the same as the radius.
312 1.0 means the distance is the same as the radius.
346 0.5 means the distance is half of the radius.
313 0.5 means the distance is half of the radius.
347 By default the distance is is 0.15
314 By default the distance is is 0.15
348 \sa exploded
315 \sa exploded
349 */
316 */
350 /*!
317 /*!
351 \qmlproperty real PieSlice::explodeDistanceFactor
318 \qmlproperty real PieSlice::explodeDistanceFactor
352 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
319 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
353 The factor is relative to pie radius. For example:
320 The factor is relative to pie radius. For example:
354 1.0 means the distance is the same as the radius.
321 1.0 means the distance is the same as the radius.
355 0.5 means the distance is half of the radius.
322 0.5 means the distance is half of the radius.
356 By default the distance is is 0.15
323 By default the distance is is 0.15
357 \sa exploded
324 \sa exploded
358 */
325 */
359
326
360 /*!
327 /*!
361 \fn void QPieSlice::explodeDistanceFactorChanged()
362 This signal is emitted when the explode distance factor of the slice has changed.
363 \sa explodeDistanceFactor
364 */
365 /*!
366 \qmlsignal PieSlice::explodeDistanceFactorChanged()
367 This signal is emitted when the explode distance factor of the slice has changed.
368 \sa explodeDistanceFactor
369 */
370
371 /*!
372 \property QPieSlice::percentage
328 \property QPieSlice::percentage
373 Percentage of the slice compared to the sum of all slices in the series.
329 Percentage of the slice compared to the sum of all slices in the series.
374 The actual value ranges from 0.0 to 1.0.
330 The actual value ranges from 0.0 to 1.0.
375 Updated automatically once the slice is added to the series.
331 Updated automatically once the slice is added to the series.
376 \sa value, QPieSeries::sum
332 \sa value, QPieSeries::sum
377 */
333 */
378 /*!
334 /*!
379 \qmlproperty real PieSlice::percentage
335 \qmlproperty real PieSlice::percentage
380 Percentage of the slice compared to the sum of all slices in the series.
336 Percentage of the slice compared to the sum of all slices in the series.
381 The actual value ranges from 0.0 to 1.0.
337 The actual value ranges from 0.0 to 1.0.
382 Updated automatically once the slice is added to the series.
338 Updated automatically once the slice is added to the series.
383 */
339 */
384
340
385 /*!
341 /*!
386 \fn void QPieSlice::percentageChanged()
342 \fn void QPieSlice::percentageChanged()
387 This signal is emitted when the percentage of the slice has changed.
343 This signal is emitted when the percentage of the slice has changed.
388 \sa percentage
344 \sa percentage
389 */
345 */
390 /*!
346 /*!
391 \qmlsignal void PieSlice::percentageChanged()
347 \qmlsignal void PieSlice::percentageChanged()
392 This signal is emitted when the percentage of the slice has changed.
348 This signal is emitted when the percentage of the slice has changed.
393 \sa percentage
349 \sa percentage
394 */
350 */
395
351
396 /*!
352 /*!
397 \property QPieSlice::startAngle
353 \property QPieSlice::startAngle
398 Defines the starting angle of this slice in the series it belongs to.
354 Defines the starting angle of this slice in the series it belongs to.
399 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
355 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
400 Updated automatically once the slice is added to the series.
356 Updated automatically once the slice is added to the series.
401 */
357 */
402 /*!
358 /*!
403 \qmlproperty real PieSlice::startAngle
359 \qmlproperty real PieSlice::startAngle
404 Defines the starting angle of this slice in the series it belongs to.
360 Defines the starting angle of this slice in the series it belongs to.
405 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
361 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
406 Updated automatically once the slice is added to the series.
362 Updated automatically once the slice is added to the series.
407 */
363 */
408
364
409 /*!
365 /*!
410 \fn void QPieSlice::startAngleChanged()
366 \fn void QPieSlice::startAngleChanged()
411 This signal is emitted when the starting angle f the slice has changed.
367 This signal is emitted when the starting angle f the slice has changed.
412 \sa startAngle
368 \sa startAngle
413 */
369 */
414 /*!
370 /*!
415 \qmlsignal PieSlice::startAngleChanged()
371 \qmlsignal PieSlice::startAngleChanged()
416 This signal is emitted when the starting angle f the slice has changed.
372 This signal is emitted when the starting angle f the slice has changed.
417 \sa startAngle
373 \sa startAngle
418 */
374 */
419
375
420 /*!
376 /*!
421 \property QPieSlice::angleSpan
377 \property QPieSlice::angleSpan
422 Span of the slice in degrees.
378 Span of the slice in degrees.
423 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
379 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
424 Updated automatically once the slice is added to the series.
380 Updated automatically once the slice is added to the series.
425 */
381 */
426 /*!
382 /*!
427 \qmlproperty real PieSlice::angleSpan
383 \qmlproperty real PieSlice::angleSpan
428 Span of the slice in degrees.
384 Span of the slice in degrees.
429 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
385 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
430 Updated automatically once the slice is added to the series.
386 Updated automatically once the slice is added to the series.
431 */
387 */
432
388
433 /*!
389 /*!
434 \fn void QPieSlice::angleSpanChanged()
390 \fn void QPieSlice::angleSpanChanged()
435 This signal is emitted when the angle span of the slice has changed.
391 This signal is emitted when the angle span of the slice has changed.
436 \sa angleSpan
392 \sa angleSpan
437 */
393 */
438 /*!
394 /*!
439 \qmlsignal PieSlice::angleSpanChanged()
395 \qmlsignal PieSlice::angleSpanChanged()
440 This signal is emitted when the angle span of the slice has changed.
396 This signal is emitted when the angle span of the slice has changed.
441 \sa angleSpan
397 \sa angleSpan
442 */
398 */
443
399
444 /*!
400 /*!
445 \fn void QPieSlice::clicked()
401 \fn void QPieSlice::clicked()
446 This signal is emitted when user has clicked the slice.
402 This signal is emitted when user has clicked the slice.
447 \sa QPieSeries::clicked()
403 \sa QPieSeries::clicked()
448 */
404 */
449 /*!
405 /*!
450 \qmlsignal PieSlice::onClicked()
406 \qmlsignal PieSlice::onClicked()
451 This signal is emitted when user has clicked the slice.
407 This signal is emitted when user has clicked the slice.
452 */
408 */
453
409
454 /*!
410 /*!
455 \fn void QPieSlice::hovered(bool state)
411 \fn void QPieSlice::hovered(bool state)
456 This signal is emitted when user has hovered over or away from the slice.
412 This signal is emitted when user has hovered over or away from the slice.
457 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
413 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
458 \sa QPieSeries::hovered()
414 \sa QPieSeries::hovered()
459 */
415 */
460 /*!
416 /*!
461 \qmlsignal PieSlice::onHovered(bool state)
417 \qmlsignal PieSlice::onHovered(bool state)
462 This signal is emitted when user has hovered over or away from the slice.
418 This signal is emitted when user has hovered over or away from the slice.
463 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
419 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
464 */
420 */
465
421
466 /*!
422 /*!
467 Constructs an empty slice with a \a parent.
423 Constructs an empty slice with a \a parent.
468 \sa QPieSeries::append(), QPieSeries::insert()
424 \sa QPieSeries::append(), QPieSeries::insert()
469 */
425 */
470 QPieSlice::QPieSlice(QObject *parent)
426 QPieSlice::QPieSlice(QObject *parent)
471 :QObject(parent),
427 :QObject(parent),
472 d_ptr(new QPieSlicePrivate(this))
428 d_ptr(new QPieSlicePrivate(this))
473 {
429 {
474
430
475 }
431 }
476
432
477 /*!
433 /*!
478 Constructs an empty slice with given \a value, \a label and a \a parent.
434 Constructs an empty slice with given \a value, \a label and a \a parent.
479 \sa QPieSeries::append(), QPieSeries::insert()
435 \sa QPieSeries::append(), QPieSeries::insert()
480 */
436 */
481 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
437 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
482 :QObject(parent),
438 :QObject(parent),
483 d_ptr(new QPieSlicePrivate(this))
439 d_ptr(new QPieSlicePrivate(this))
484 {
440 {
485 setValue(value);
441 setValue(value);
486 setLabel(label);
442 setLabel(label);
487 }
443 }
488
444
489 /*!
445 /*!
490 Destroys the slice.
446 Destroys the slice.
491 User should not delete the slice if it has been added to the series.
447 User should not delete the slice if it has been added to the series.
492 */
448 */
493 QPieSlice::~QPieSlice()
449 QPieSlice::~QPieSlice()
494 {
450 {
495
451
496 }
452 }
497
453
498 void QPieSlice::setLabel(QString label)
454 void QPieSlice::setLabel(QString label)
499 {
455 {
500 if (d_ptr->m_data.m_labelText != label) {
456 if (d_ptr->m_data.m_labelText != label) {
501 d_ptr->m_data.m_labelText = label;
457 d_ptr->m_data.m_labelText = label;
502 emit labelChanged();
458 emit labelChanged();
503 }
459 }
504 }
460 }
505
461
506 QString QPieSlice::label() const
462 QString QPieSlice::label() const
507 {
463 {
508 return d_ptr->m_data.m_labelText;
464 return d_ptr->m_data.m_labelText;
509 }
465 }
510
466
511 void QPieSlice::setValue(qreal value)
467 void QPieSlice::setValue(qreal value)
512 {
468 {
513 value = qAbs(value); // negative values not allowed
469 value = qAbs(value); // negative values not allowed
514 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
470 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
515 d_ptr->m_data.m_value = value;
471 d_ptr->m_data.m_value = value;
516 emit valueChanged();
472 emit valueChanged();
517 }
473 }
518 }
474 }
519
475
520 qreal QPieSlice::value() const
476 qreal QPieSlice::value() const
521 {
477 {
522 return d_ptr->m_data.m_value;
478 return d_ptr->m_data.m_value;
523 }
479 }
524
480
525 void QPieSlice::setLabelVisible(bool visible)
481 void QPieSlice::setLabelVisible(bool visible)
526 {
482 {
527 if (d_ptr->m_data.m_isLabelVisible != visible) {
483 if (d_ptr->m_data.m_isLabelVisible != visible) {
528 d_ptr->m_data.m_isLabelVisible = visible;
484 d_ptr->m_data.m_isLabelVisible = visible;
529 emit labelVisibleChanged();
485 emit labelVisibleChanged();
530 }
486 }
531 }
487 }
532
488
533 bool QPieSlice::isLabelVisible() const
489 bool QPieSlice::isLabelVisible() const
534 {
490 {
535 return d_ptr->m_data.m_isLabelVisible;
491 return d_ptr->m_data.m_isLabelVisible;
536 }
492 }
537
493
538 void QPieSlice::setExploded(bool exploded)
494 void QPieSlice::setExploded(bool exploded)
539 {
495 {
540 if (d_ptr->m_data.m_isExploded != exploded) {
496 if (d_ptr->m_data.m_isExploded != exploded) {
541 d_ptr->m_data.m_isExploded = exploded;
497 d_ptr->m_data.m_isExploded = exploded;
542 emit explodedChanged();
498 emit d_ptr->explodedChanged();
543 }
499 }
544 }
500 }
545
501
546 QPieSlice::LabelPosition QPieSlice::labelPosition()
502 QPieSlice::LabelPosition QPieSlice::labelPosition()
547 {
503 {
548 return d_ptr->m_data.m_labelPosition;
504 return d_ptr->m_data.m_labelPosition;
549 }
505 }
550
506
551 void QPieSlice::setLabelPosition(LabelPosition position)
507 void QPieSlice::setLabelPosition(LabelPosition position)
552 {
508 {
553 if (d_ptr->m_data.m_labelPosition != position) {
509 if (d_ptr->m_data.m_labelPosition != position) {
554 d_ptr->m_data.m_labelPosition = position;
510 d_ptr->m_data.m_labelPosition = position;
555 emit labelPositionChanged();
511 emit d_ptr->labelPositionChanged();
556 }
512 }
557 }
513 }
558
514
559 bool QPieSlice::isExploded() const
515 bool QPieSlice::isExploded() const
560 {
516 {
561 return d_ptr->m_data.m_isExploded;
517 return d_ptr->m_data.m_isExploded;
562 }
518 }
563
519
564 void QPieSlice::setPen(const QPen &pen)
520 void QPieSlice::setPen(const QPen &pen)
565 {
521 {
566 d_ptr->setPen(pen, false);
522 d_ptr->setPen(pen, false);
567 }
523 }
568
524
569 QPen QPieSlice::pen() const
525 QPen QPieSlice::pen() const
570 {
526 {
571 return d_ptr->m_data.m_slicePen;
527 return d_ptr->m_data.m_slicePen;
572 }
528 }
573
529
574 QColor QPieSlice::borderColor()
530 QColor QPieSlice::borderColor()
575 {
531 {
576 return pen().color();
532 return pen().color();
577 }
533 }
578
534
579 void QPieSlice::setBorderColor(QColor color)
535 void QPieSlice::setBorderColor(QColor color)
580 {
536 {
581 QPen p = pen();
537 QPen p = pen();
582 if (color != p.color()) {
538 if (color != p.color()) {
583 p.setColor(color);
539 p.setColor(color);
584 setPen(p);
540 setPen(p);
585 }
541 }
586 }
542 }
587
543
588 int QPieSlice::borderWidth()
544 int QPieSlice::borderWidth()
589 {
545 {
590 return pen().width();
546 return pen().width();
591 }
547 }
592
548
593 void QPieSlice::setBorderWidth(int width)
549 void QPieSlice::setBorderWidth(int width)
594 {
550 {
595 QPen p = pen();
551 QPen p = pen();
596 if (width != p.width()) {
552 if (width != p.width()) {
597 p.setWidth(width);
553 p.setWidth(width);
598 setPen(p);
554 setPen(p);
599 }
555 }
600 }
556 }
601
557
602 void QPieSlice::setBrush(const QBrush &brush)
558 void QPieSlice::setBrush(const QBrush &brush)
603 {
559 {
604 d_ptr->setBrush(brush, false);
560 d_ptr->setBrush(brush, false);
605 }
561 }
606
562
607 QBrush QPieSlice::brush() const
563 QBrush QPieSlice::brush() const
608 {
564 {
609 return d_ptr->m_data.m_sliceBrush;
565 return d_ptr->m_data.m_sliceBrush;
610 }
566 }
611
567
612 QColor QPieSlice::color()
568 QColor QPieSlice::color()
613 {
569 {
614 return brush().color();
570 return brush().color();
615 }
571 }
616
572
617 void QPieSlice::setColor(QColor color)
573 void QPieSlice::setColor(QColor color)
618 {
574 {
619 QBrush b = brush();
575 QBrush b = brush();
620 if (color != b.color()) {
576 if (color != b.color()) {
621 b.setColor(color);
577 b.setColor(color);
622 setBrush(b);
578 setBrush(b);
623 }
579 }
624 }
580 }
625
581
626 void QPieSlice::setLabelBrush(const QBrush &brush)
582 void QPieSlice::setLabelBrush(const QBrush &brush)
627 {
583 {
628 d_ptr->setLabelBrush(brush, false);
584 d_ptr->setLabelBrush(brush, false);
629 }
585 }
630
586
631 QBrush QPieSlice::labelBrush() const
587 QBrush QPieSlice::labelBrush() const
632 {
588 {
633 return d_ptr->m_data.m_labelBrush;
589 return d_ptr->m_data.m_labelBrush;
634 }
590 }
635
591
636 QColor QPieSlice::labelColor()
592 QColor QPieSlice::labelColor()
637 {
593 {
638 return labelBrush().color();
594 return labelBrush().color();
639 }
595 }
640
596
641 void QPieSlice::setLabelColor(QColor color)
597 void QPieSlice::setLabelColor(QColor color)
642 {
598 {
643 QBrush b = labelBrush();
599 QBrush b = labelBrush();
644 if (color != b.color()) {
600 if (color != b.color()) {
645 b.setColor(color);
601 b.setColor(color);
646 setLabelBrush(b);
602 setLabelBrush(b);
647 }
603 }
648 }
604 }
649
605
650 void QPieSlice::setLabelFont(const QFont &font)
606 void QPieSlice::setLabelFont(const QFont &font)
651 {
607 {
652 d_ptr->setLabelFont(font, false);
608 d_ptr->setLabelFont(font, false);
653 }
609 }
654
610
655 QFont QPieSlice::labelFont() const
611 QFont QPieSlice::labelFont() const
656 {
612 {
657 return d_ptr->m_data.m_labelFont;
613 return d_ptr->m_data.m_labelFont;
658 }
614 }
659
615
660 void QPieSlice::setLabelArmLengthFactor(qreal factor)
616 void QPieSlice::setLabelArmLengthFactor(qreal factor)
661 {
617 {
662 if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) {
618 if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) {
663 d_ptr->m_data.m_labelArmLengthFactor = factor;
619 d_ptr->m_data.m_labelArmLengthFactor = factor;
664 emit labelArmLengthFactorChanged();
620 emit d_ptr->labelArmLengthFactorChanged();
665 }
621 }
666 }
622 }
667
623
668 qreal QPieSlice::labelArmLengthFactor() const
624 qreal QPieSlice::labelArmLengthFactor() const
669 {
625 {
670 return d_ptr->m_data.m_labelArmLengthFactor;
626 return d_ptr->m_data.m_labelArmLengthFactor;
671 }
627 }
672
628
673 void QPieSlice::setExplodeDistanceFactor(qreal factor)
629 void QPieSlice::setExplodeDistanceFactor(qreal factor)
674 {
630 {
675 if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) {
631 if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) {
676 d_ptr->m_data.m_explodeDistanceFactor = factor;
632 d_ptr->m_data.m_explodeDistanceFactor = factor;
677 emit explodeDistanceFactorChanged();
633 emit d_ptr->explodeDistanceFactorChanged();
678 }
634 }
679 }
635 }
680
636
681 qreal QPieSlice::explodeDistanceFactor() const
637 qreal QPieSlice::explodeDistanceFactor() const
682 {
638 {
683 return d_ptr->m_data.m_explodeDistanceFactor;
639 return d_ptr->m_data.m_explodeDistanceFactor;
684 }
640 }
685
641
686 qreal QPieSlice::percentage() const
642 qreal QPieSlice::percentage() const
687 {
643 {
688 return d_ptr->m_data.m_percentage;
644 return d_ptr->m_data.m_percentage;
689 }
645 }
690
646
691 qreal QPieSlice::startAngle() const
647 qreal QPieSlice::startAngle() const
692 {
648 {
693 return d_ptr->m_data.m_startAngle;
649 return d_ptr->m_data.m_startAngle;
694 }
650 }
695
651
696 qreal QPieSlice::angleSpan() const
652 qreal QPieSlice::angleSpan() const
697 {
653 {
698 return d_ptr->m_data.m_angleSpan;
654 return d_ptr->m_data.m_angleSpan;
699 }
655 }
700
656
701 /*!
657 /*!
702 Returns the series that this slice belongs to.
658 Returns the series that this slice belongs to.
703
659
704 \sa QPieSeries::append()
660 \sa QPieSeries::append()
705 */
661 */
706 QPieSeries *QPieSlice::series() const
662 QPieSeries *QPieSlice::series() const
707 {
663 {
708 return d_ptr->m_series;
664 return d_ptr->m_series;
709 }
665 }
710
666
711 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
667 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
712 :QObject(parent),
668 :QObject(parent),
713 q_ptr(parent),
669 q_ptr(parent),
714 m_series(0)
670 m_series(0)
715 {
671 {
716
672
717 }
673 }
718
674
719 QPieSlicePrivate::~QPieSlicePrivate()
675 QPieSlicePrivate::~QPieSlicePrivate()
720 {
676 {
721
677
722 }
678 }
723
679
724 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
680 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
725 {
681 {
726 return slice->d_func();
682 return slice->d_func();
727 }
683 }
728
684
729 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
685 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
730 {
686 {
731 if (m_data.m_slicePen != pen) {
687 if (m_data.m_slicePen != pen) {
732
688
733 QPen oldPen = m_data.m_slicePen;
689 QPen oldPen = m_data.m_slicePen;
734
690
735 m_data.m_slicePen = pen;
691 m_data.m_slicePen = pen;
736 m_data.m_slicePen.setThemed(themed);
692 m_data.m_slicePen.setThemed(themed);
737
693
738 emit q_ptr->penChanged();
694 emit q_ptr->penChanged();
739 if (oldPen.color() != pen.color())
695 if (oldPen.color() != pen.color())
740 emit q_ptr->borderColorChanged();
696 emit q_ptr->borderColorChanged();
741 if (oldPen.width() != pen.width())
697 if (oldPen.width() != pen.width())
742 emit q_ptr->borderWidthChanged();
698 emit q_ptr->borderWidthChanged();
743 }
699 }
744 }
700 }
745
701
746 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
702 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
747 {
703 {
748 if (m_data.m_sliceBrush != brush) {
704 if (m_data.m_sliceBrush != brush) {
749
705
750 QBrush oldBrush = m_data.m_sliceBrush;
706 QBrush oldBrush = m_data.m_sliceBrush;
751
707
752 m_data.m_sliceBrush = brush;
708 m_data.m_sliceBrush = brush;
753 m_data.m_sliceBrush.setThemed(themed);
709 m_data.m_sliceBrush.setThemed(themed);
754
710
755 emit q_ptr->brushChanged();
711 emit q_ptr->brushChanged();
756 if (oldBrush.color() != brush.color())
712 if (oldBrush.color() != brush.color())
757 emit q_ptr->colorChanged();
713 emit q_ptr->colorChanged();
758 }
714 }
759 }
715 }
760
716
761 void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed)
717 void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed)
762 {
718 {
763 if (m_data.m_labelBrush != brush) {
719 if (m_data.m_labelBrush != brush) {
764
720
765 QBrush oldBrush = m_data.m_labelBrush;
721 QBrush oldBrush = m_data.m_labelBrush;
766
722
767 m_data.m_labelBrush = brush;
723 m_data.m_labelBrush = brush;
768 m_data.m_labelBrush.setThemed(themed);
724 m_data.m_labelBrush.setThemed(themed);
769
725
770 emit q_ptr->labelBrushChanged();
726 emit q_ptr->labelBrushChanged();
771 if (oldBrush.color() != brush.color())
727 if (oldBrush.color() != brush.color())
772 emit q_ptr->labelColorChanged();
728 emit q_ptr->labelColorChanged();
773 }
729 }
774 }
730 }
775
731
776 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
732 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
777 {
733 {
778 if (m_data.m_labelFont != font) {
734 if (m_data.m_labelFont != font) {
779 m_data.m_labelFont = font;
735 m_data.m_labelFont = font;
780 m_data.m_labelFont.setThemed(themed);
736 m_data.m_labelFont.setThemed(themed);
781 emit q_ptr->labelFontChanged();
737 emit q_ptr->labelFontChanged();
782 }
738 }
783 }
739 }
784
740
785 void QPieSlicePrivate::setPercentage(qreal percentage)
741 void QPieSlicePrivate::setPercentage(qreal percentage)
786 {
742 {
787 if (!qFuzzyIsNull(m_data.m_percentage - percentage)) {
743 if (!qFuzzyIsNull(m_data.m_percentage - percentage)) {
788 m_data.m_percentage = percentage;
744 m_data.m_percentage = percentage;
789 emit q_ptr->percentageChanged();
745 emit q_ptr->percentageChanged();
790 }
746 }
791 }
747 }
792
748
793 void QPieSlicePrivate::setStartAngle(qreal angle)
749 void QPieSlicePrivate::setStartAngle(qreal angle)
794 {
750 {
795 if (!qFuzzyIsNull(m_data.m_startAngle - angle)) {
751 if (!qFuzzyIsNull(m_data.m_startAngle - angle)) {
796 m_data.m_startAngle = angle;
752 m_data.m_startAngle = angle;
797 emit q_ptr->startAngleChanged();
753 emit q_ptr->startAngleChanged();
798 }
754 }
799 }
755 }
800
756
801 void QPieSlicePrivate::setAngleSpan(qreal span)
757 void QPieSlicePrivate::setAngleSpan(qreal span)
802 {
758 {
803 if (!qFuzzyIsNull(m_data.m_angleSpan - span)) {
759 if (!qFuzzyIsNull(m_data.m_angleSpan - span)) {
804 m_data.m_angleSpan = span;
760 m_data.m_angleSpan = span;
805 emit q_ptr->angleSpanChanged();
761 emit q_ptr->angleSpanChanged();
806 }
762 }
807 }
763 }
808
764
809 QTCOMMERCIALCHART_END_NAMESPACE
765 QTCOMMERCIALCHART_END_NAMESPACE
810
766
811 QTCOMMERCIALCHART_USE_NAMESPACE
767 QTCOMMERCIALCHART_USE_NAMESPACE
812 #include "moc_qpieslice.cpp"
768 #include "moc_qpieslice.cpp"
813 #include "moc_qpieslice_p.cpp"
769 #include "moc_qpieslice_p.cpp"
@@ -1,149 +1,145
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 class QPieSeries;
32 class QPieSeries;
33
33
34 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
34 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
35 {
35 {
36 Q_OBJECT
36 Q_OBJECT
37 Q_ENUMS(LabelPosition)
37 Q_ENUMS(LabelPosition)
38 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
38 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
39 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
39 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
40 Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged)
40 Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged)
41 Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition NOTIFY labelPositionChanged)
41 Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition)
42 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded NOTIFY explodedChanged)
42 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded)
43 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
43 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
44 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
44 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
45 Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged)
45 Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged)
46 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
46 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
47 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
47 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
48 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
48 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
49 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
49 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
50 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
50 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
51 Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor NOTIFY labelArmLengthFactorChanged)
51 Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor)
52 Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor NOTIFY explodeDistanceFactorChanged)
52 Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor)
53 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
53 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
54 Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged)
54 Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged)
55 Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged)
55 Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged)
56
56
57 public:
57 public:
58 enum LabelPosition {
58 enum LabelPosition {
59 LabelOutside,
59 LabelOutside,
60 LabelInside
60 LabelInside
61 };
61 };
62
62
63 public:
63 public:
64 explicit QPieSlice(QObject *parent = 0);
64 explicit QPieSlice(QObject *parent = 0);
65 QPieSlice(QString label, qreal value, QObject *parent = 0);
65 QPieSlice(QString label, qreal value, QObject *parent = 0);
66 virtual ~QPieSlice();
66 virtual ~QPieSlice();
67
67
68 void setLabel(QString label);
68 void setLabel(QString label);
69 QString label() const;
69 QString label() const;
70
70
71 void setValue(qreal value);
71 void setValue(qreal value);
72 qreal value() const;
72 qreal value() const;
73
73
74 void setLabelVisible(bool visible = true);
74 void setLabelVisible(bool visible = true);
75 bool isLabelVisible() const;
75 bool isLabelVisible() const;
76
76
77 LabelPosition labelPosition();
77 LabelPosition labelPosition();
78 void setLabelPosition(LabelPosition position);
78 void setLabelPosition(LabelPosition position);
79
79
80 void setExploded(bool exploded = true);
80 void setExploded(bool exploded = true);
81 bool isExploded() const;
81 bool isExploded() const;
82
82
83 void setPen(const QPen &pen);
83 void setPen(const QPen &pen);
84 QPen pen() const;
84 QPen pen() const;
85
85
86 QColor borderColor();
86 QColor borderColor();
87 void setBorderColor(QColor color);
87 void setBorderColor(QColor color);
88
88
89 int borderWidth();
89 int borderWidth();
90 void setBorderWidth(int width);
90 void setBorderWidth(int width);
91
91
92 void setBrush(const QBrush &brush);
92 void setBrush(const QBrush &brush);
93 QBrush brush() const;
93 QBrush brush() const;
94
94
95 QColor color();
95 QColor color();
96 void setColor(QColor color);
96 void setColor(QColor color);
97
97
98 void setLabelBrush(const QBrush &brush);
98 void setLabelBrush(const QBrush &brush);
99 QBrush labelBrush() const;
99 QBrush labelBrush() const;
100
100
101 QColor labelColor();
101 QColor labelColor();
102 void setLabelColor(QColor color);
102 void setLabelColor(QColor color);
103
103
104 void setLabelFont(const QFont &font);
104 void setLabelFont(const QFont &font);
105 QFont labelFont() const;
105 QFont labelFont() const;
106
106
107 void setLabelArmLengthFactor(qreal factor);
107 void setLabelArmLengthFactor(qreal factor);
108 qreal labelArmLengthFactor() const;
108 qreal labelArmLengthFactor() const;
109
109
110 void setExplodeDistanceFactor(qreal factor);
110 void setExplodeDistanceFactor(qreal factor);
111 qreal explodeDistanceFactor() const;
111 qreal explodeDistanceFactor() const;
112
112
113 qreal percentage() const;
113 qreal percentage() const;
114 qreal startAngle() const;
114 qreal startAngle() const;
115 qreal angleSpan() const;
115 qreal angleSpan() const;
116
116
117 QPieSeries *series() const;
117 QPieSeries *series() const;
118
118
119 Q_SIGNALS:
119 Q_SIGNALS:
120 void clicked();
121 void hovered(bool state);
120 void labelChanged();
122 void labelChanged();
121 void valueChanged();
123 void valueChanged();
122 void labelVisibleChanged();
124 void labelVisibleChanged();
123 void labelPositionChanged();
124 void explodedChanged();
125 void penChanged();
125 void penChanged();
126 void brushChanged();
126 void brushChanged();
127 void labelBrushChanged();
127 void labelBrushChanged();
128 void labelFontChanged();
128 void labelFontChanged();
129 void labelArmLengthFactorChanged();
130 void explodeDistanceFactorChanged();
131 void percentageChanged();
129 void percentageChanged();
132 void startAngleChanged();
130 void startAngleChanged();
133 void angleSpanChanged();
131 void angleSpanChanged();
134 void colorChanged();
132 void colorChanged();
135 void borderColorChanged();
133 void borderColorChanged();
136 void borderWidthChanged();
134 void borderWidthChanged();
137 void labelColorChanged();
135 void labelColorChanged();
138 void clicked();
139 void hovered(bool state);
140
136
141 private:
137 private:
142 QPieSlicePrivate * const d_ptr;
138 QPieSlicePrivate * const d_ptr;
143 Q_DECLARE_PRIVATE(QPieSlice)
139 Q_DECLARE_PRIVATE(QPieSlice)
144 Q_DISABLE_COPY(QPieSlice)
140 Q_DISABLE_COPY(QPieSlice)
145 };
141 };
146
142
147 QTCOMMERCIALCHART_END_NAMESPACE
143 QTCOMMERCIALCHART_END_NAMESPACE
148
144
149 #endif // QPIESLICE_H
145 #endif // QPIESLICE_H
@@ -1,74 +1,80
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 QPIESLICE_P_H
30 #ifndef QPIESLICE_P_H
31 #define QPIESLICE_P_H
31 #define QPIESLICE_P_H
32
32
33 #include <QObject>
33 #include <QObject>
34 #include "qpieslice.h"
34 #include "qpieslice.h"
35 #include "pieslicedata_p.h"
35 #include "pieslicedata_p.h"
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 class QPieSeries;
38 class QPieSeries;
39
39
40 class QPieSlicePrivate : public QObject
40 class QPieSlicePrivate : public QObject
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43
43
44 public:
44 public:
45 QPieSlicePrivate(QPieSlice *parent);
45 QPieSlicePrivate(QPieSlice *parent);
46 ~QPieSlicePrivate();
46 ~QPieSlicePrivate();
47
47
48 static QPieSlicePrivate* fromSlice(QPieSlice *slice);
48 static QPieSlicePrivate* fromSlice(QPieSlice *slice);
49
49
50 void setPen(const QPen &pen, bool themed);
50 void setPen(const QPen &pen, bool themed);
51 void setBrush(const QBrush &brush, bool themed);
51 void setBrush(const QBrush &brush, bool themed);
52 void setLabelBrush(const QBrush &brush, bool themed);
52 void setLabelBrush(const QBrush &brush, bool themed);
53 void setLabelFont(const QFont &font, bool themed);
53 void setLabelFont(const QFont &font, bool themed);
54
54
55 void setPercentage(qreal percentage);
55 void setPercentage(qreal percentage);
56 void setStartAngle(qreal angle);
56 void setStartAngle(qreal angle);
57 void setAngleSpan(qreal span);
57 void setAngleSpan(qreal span);
58
58
59 Q_SIGNALS:
60 void labelPositionChanged();
61 void explodedChanged();
62 void labelArmLengthFactorChanged();
63 void explodeDistanceFactorChanged();
64
59 private:
65 private:
60 friend class QPieSeries;
66 friend class QPieSeries;
61 friend class QPieSeriesPrivate;
67 friend class QPieSeriesPrivate;
62 friend class ChartTheme;
68 friend class ChartTheme;
63 friend class PieChartItem;
69 friend class PieChartItem;
64
70
65 QPieSlice * const q_ptr;
71 QPieSlice * const q_ptr;
66 Q_DECLARE_PUBLIC(QPieSlice)
72 Q_DECLARE_PUBLIC(QPieSlice)
67
73
68 PieSliceData m_data;
74 PieSliceData m_data;
69 QPieSeries *m_series;
75 QPieSeries *m_series;
70 };
76 };
71
77
72 QTCOMMERCIALCHART_END_NAMESPACE
78 QTCOMMERCIALCHART_END_NAMESPACE
73
79
74 #endif // QPIESLICE_P_H
80 #endif // QPIESLICE_P_H
@@ -1,304 +1,296
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.labelBrush(), QBrush());
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.labelBrush(), QBrush());
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()));
114 QSignalSpy penSpy(&slice, SIGNAL(penChanged()));
113 QSignalSpy penSpy(&slice, SIGNAL(penChanged()));
115 QSignalSpy brushSpy(&slice, SIGNAL(brushChanged()));
114 QSignalSpy brushSpy(&slice, SIGNAL(brushChanged()));
116 QSignalSpy labelBrushSpy(&slice, SIGNAL(labelBrushChanged()));
115 QSignalSpy labelBrushSpy(&slice, SIGNAL(labelBrushChanged()));
117 QSignalSpy labelFontSpy(&slice, SIGNAL(labelFontChanged()));
116 QSignalSpy labelFontSpy(&slice, SIGNAL(labelFontChanged()));
118 QSignalSpy labelPositionSpy(&slice, SIGNAL(labelPositionChanged()));
119 QSignalSpy labelArmLengthFactorSpy(&slice, SIGNAL(labelArmLengthFactorChanged()));
120 QSignalSpy explodeDistanceFactorSpy(&slice, SIGNAL(explodeDistanceFactorChanged()));
121 QSignalSpy colorSpy(&slice, SIGNAL(colorChanged()));
117 QSignalSpy colorSpy(&slice, SIGNAL(colorChanged()));
122 QSignalSpy borderColorSpy(&slice, SIGNAL(borderColorChanged()));
118 QSignalSpy borderColorSpy(&slice, SIGNAL(borderColorChanged()));
123 QSignalSpy borderWidthSpy(&slice, SIGNAL(borderWidthChanged()));
119 QSignalSpy borderWidthSpy(&slice, SIGNAL(borderWidthChanged()));
124 QSignalSpy labelColorSpy(&slice, SIGNAL(labelColorChanged()));
120 QSignalSpy labelColorSpy(&slice, SIGNAL(labelColorChanged()));
125
121
126 // percentageChanged(), startAngleChanged() and angleSpanChanged() signals tested at tst_qpieseries::calculatedValues()
122 // percentageChanged(), startAngleChanged() and angleSpanChanged() signals tested at tst_qpieseries::calculatedValues()
127
123
128 // set everything twice to see we do not get unnecessary signals
124 // set everything twice to see we do not get unnecessary signals
129 slice.setValue(1.0);
125 slice.setValue(1.0);
130 slice.setValue(-1.0);
126 slice.setValue(-1.0);
131 QCOMPARE(slice.value(), 1.0);
127 QCOMPARE(slice.value(), 1.0);
132 slice.setLabel("foobar");
128 slice.setLabel("foobar");
133 slice.setLabel("foobar");
129 slice.setLabel("foobar");
134 slice.setLabelVisible();
130 slice.setLabelVisible();
135 slice.setLabelVisible();
131 slice.setLabelVisible();
136 slice.setExploded();
132 slice.setExploded();
137 slice.setExploded();
133 slice.setExploded();
138 slice.setPen(QPen(Qt::red));
134 slice.setPen(QPen(Qt::red));
139 slice.setPen(QPen(QBrush(Qt::red), 3));
135 slice.setPen(QPen(QBrush(Qt::red), 3));
140 slice.setBrush(QBrush(Qt::red));
136 slice.setBrush(QBrush(Qt::red));
141 slice.setBrush(QBrush(Qt::red));
137 slice.setBrush(QBrush(Qt::red));
142 slice.setLabelBrush(QBrush(Qt::green));
138 slice.setLabelBrush(QBrush(Qt::green));
143 slice.setLabelBrush(QBrush(Qt::green));
139 slice.setLabelBrush(QBrush(Qt::green));
144 slice.setLabelFont(QFont("Tahoma"));
140 slice.setLabelFont(QFont("Tahoma"));
145 slice.setLabelFont(QFont("Tahoma"));
141 slice.setLabelFont(QFont("Tahoma"));
146 slice.setLabelPosition(QPieSlice::LabelInside);
142 slice.setLabelPosition(QPieSlice::LabelInside);
147 slice.setLabelPosition(QPieSlice::LabelInside);
143 slice.setLabelPosition(QPieSlice::LabelInside);
148 slice.setLabelArmLengthFactor(0.1);
144 slice.setLabelArmLengthFactor(0.1);
149 slice.setLabelArmLengthFactor(0.1);
145 slice.setLabelArmLengthFactor(0.1);
150 slice.setExplodeDistanceFactor(0.1);
146 slice.setExplodeDistanceFactor(0.1);
151 slice.setExplodeDistanceFactor(0.1);
147 slice.setExplodeDistanceFactor(0.1);
152
148
153 TRY_COMPARE(valueSpy.count(), 1);
149 TRY_COMPARE(valueSpy.count(), 1);
154 TRY_COMPARE(labelSpy.count(), 1);
150 TRY_COMPARE(labelSpy.count(), 1);
155 TRY_COMPARE(explodedSpy.count(), 1);
156 TRY_COMPARE(penSpy.count(), 2);
151 TRY_COMPARE(penSpy.count(), 2);
157 TRY_COMPARE(brushSpy.count(), 1);
152 TRY_COMPARE(brushSpy.count(), 1);
158 TRY_COMPARE(labelBrushSpy.count(), 1);
153 TRY_COMPARE(labelBrushSpy.count(), 1);
159 TRY_COMPARE(labelFontSpy.count(), 1);
154 TRY_COMPARE(labelFontSpy.count(), 1);
160 TRY_COMPARE(labelPositionSpy.count(), 1);
161 TRY_COMPARE(labelArmLengthFactorSpy.count(), 1);
162 TRY_COMPARE(explodeDistanceFactorSpy.count(), 1);
163 TRY_COMPARE(colorSpy.count(), 1);
155 TRY_COMPARE(colorSpy.count(), 1);
164 TRY_COMPARE(borderColorSpy.count(), 1);
156 TRY_COMPARE(borderColorSpy.count(), 1);
165 TRY_COMPARE(borderWidthSpy.count(), 1);
157 TRY_COMPARE(borderWidthSpy.count(), 1);
166 TRY_COMPARE(labelColorSpy.count(), 1);
158 TRY_COMPARE(labelColorSpy.count(), 1);
167 }
159 }
168
160
169 void tst_qpieslice::customize()
161 void tst_qpieslice::customize()
170 {
162 {
171 // create a pie series
163 // create a pie series
172 QPieSeries *series = new QPieSeries();
164 QPieSeries *series = new QPieSeries();
173 QPieSlice *s1 = series->append("slice 1", 1);
165 QPieSlice *s1 = series->append("slice 1", 1);
174 QPieSlice *s2 = series->append("slice 2", 2);
166 QPieSlice *s2 = series->append("slice 2", 2);
175 series->append("slice 3", 3);
167 series->append("slice 3", 3);
176
168
177 // customize a slice
169 // customize a slice
178 QPen p1(Qt::red);
170 QPen p1(Qt::red);
179 s1->setPen(p1);
171 s1->setPen(p1);
180 QBrush b1(Qt::red);
172 QBrush b1(Qt::red);
181 s1->setBrush(b1);
173 s1->setBrush(b1);
182 s1->setLabelBrush(b1);
174 s1->setLabelBrush(b1);
183 QFont f1("Consolas");
175 QFont f1("Consolas");
184 s1->setLabelFont(f1);
176 s1->setLabelFont(f1);
185
177
186 // add series to the chart
178 // add series to the chart
187 QChartView view(new QChart());
179 QChartView view(new QChart());
188 view.resize(200, 200);
180 view.resize(200, 200);
189 view.chart()->addSeries(series);
181 view.chart()->addSeries(series);
190 view.show();
182 view.show();
191 QTest::qWaitForWindowShown(&view);
183 QTest::qWaitForWindowShown(&view);
192 //QTest::qWait(1000);
184 //QTest::qWait(1000);
193
185
194 // check that customizations persist
186 // check that customizations persist
195 QCOMPARE(s1->pen(), p1);
187 QCOMPARE(s1->pen(), p1);
196 QCOMPARE(s1->brush(), b1);
188 QCOMPARE(s1->brush(), b1);
197 QCOMPARE(s1->labelBrush(), b1);
189 QCOMPARE(s1->labelBrush(), b1);
198 QCOMPARE(s1->labelFont(), f1);
190 QCOMPARE(s1->labelFont(), f1);
199
191
200 // remove a slice
192 // remove a slice
201 series->remove(s2);
193 series->remove(s2);
202 QCOMPARE(s1->pen(), p1);
194 QCOMPARE(s1->pen(), p1);
203 QCOMPARE(s1->brush(), b1);
195 QCOMPARE(s1->brush(), b1);
204 QCOMPARE(s1->labelBrush(), b1);
196 QCOMPARE(s1->labelBrush(), b1);
205 QCOMPARE(s1->labelFont(), f1);
197 QCOMPARE(s1->labelFont(), f1);
206
198
207 // add a slice
199 // add a slice
208 series->append("slice 4", 4);
200 series->append("slice 4", 4);
209 QCOMPARE(s1->pen(), p1);
201 QCOMPARE(s1->pen(), p1);
210 QCOMPARE(s1->brush(), b1);
202 QCOMPARE(s1->brush(), b1);
211 QCOMPARE(s1->labelBrush(), b1);
203 QCOMPARE(s1->labelBrush(), b1);
212 QCOMPARE(s1->labelFont(), f1);
204 QCOMPARE(s1->labelFont(), f1);
213
205
214 // insert a slice
206 // insert a slice
215 series->insert(0, new QPieSlice("slice 5", 5));
207 series->insert(0, new QPieSlice("slice 5", 5));
216 QCOMPARE(s1->pen(), p1);
208 QCOMPARE(s1->pen(), p1);
217 QCOMPARE(s1->brush(), b1);
209 QCOMPARE(s1->brush(), b1);
218 QCOMPARE(s1->labelBrush(), b1);
210 QCOMPARE(s1->labelBrush(), b1);
219 QCOMPARE(s1->labelFont(), f1);
211 QCOMPARE(s1->labelFont(), f1);
220
212
221 // change theme
213 // change theme
222 // theme will overwrite customizations
214 // theme will overwrite customizations
223 view.chart()->setTheme(QChart::ChartThemeHighContrast);
215 view.chart()->setTheme(QChart::ChartThemeHighContrast);
224 QVERIFY(s1->pen() != p1);
216 QVERIFY(s1->pen() != p1);
225 QVERIFY(s1->brush() != b1);
217 QVERIFY(s1->brush() != b1);
226 QVERIFY(s1->labelBrush() != b1);
218 QVERIFY(s1->labelBrush() != b1);
227 QVERIFY(s1->labelFont() != f1);
219 QVERIFY(s1->labelFont() != f1);
228 }
220 }
229
221
230 void tst_qpieslice::mouseClick()
222 void tst_qpieslice::mouseClick()
231 {
223 {
232 // create a pie series
224 // create a pie series
233 QPieSeries *series = new QPieSeries();
225 QPieSeries *series = new QPieSeries();
234 series->setPieSize(1.0);
226 series->setPieSize(1.0);
235 QPieSlice *s1 = series->append("slice 1", 1);
227 QPieSlice *s1 = series->append("slice 1", 1);
236 QPieSlice *s2 = series->append("slice 2", 2);
228 QPieSlice *s2 = series->append("slice 2", 2);
237 QPieSlice *s3 = series->append("slice 3", 3);
229 QPieSlice *s3 = series->append("slice 3", 3);
238 QSignalSpy clickSpy1(s1, SIGNAL(clicked()));
230 QSignalSpy clickSpy1(s1, SIGNAL(clicked()));
239 QSignalSpy clickSpy2(s2, SIGNAL(clicked()));
231 QSignalSpy clickSpy2(s2, SIGNAL(clicked()));
240 QSignalSpy clickSpy3(s3, SIGNAL(clicked()));
232 QSignalSpy clickSpy3(s3, SIGNAL(clicked()));
241
233
242 // add series to the chart
234 // add series to the chart
243 QChartView view(new QChart());
235 QChartView view(new QChart());
244 view.chart()->legend()->setVisible(false);
236 view.chart()->legend()->setVisible(false);
245 view.resize(200, 200);
237 view.resize(200, 200);
246 view.chart()->addSeries(series);
238 view.chart()->addSeries(series);
247 view.show();
239 view.show();
248 QTest::qWaitForWindowShown(&view);
240 QTest::qWaitForWindowShown(&view);
249
241
250 // simulate clicks
242 // simulate clicks
251 // pie rectangle: QRectF(60,60 121x121)
243 // pie rectangle: QRectF(60,60 121x121)
252 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1
244 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1
253 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(146, 136)); // inside slice 2
245 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(146, 136)); // inside slice 2
254 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(91, 119)); // inside slice 3
246 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(91, 119)); // inside slice 3
255 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(70, 70)); // inside pie rectangle but not inside a slice
247 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(70, 70)); // inside pie rectangle but not inside a slice
256 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(170, 170)); // inside pie rectangle but not inside a slice
248 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(170, 170)); // inside pie rectangle but not inside a slice
257 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
249 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
258 QCOMPARE(clickSpy1.count(), 1);
250 QCOMPARE(clickSpy1.count(), 1);
259 QCOMPARE(clickSpy2.count(), 1);
251 QCOMPARE(clickSpy2.count(), 1);
260 QCOMPARE(clickSpy3.count(), 1);
252 QCOMPARE(clickSpy3.count(), 1);
261 }
253 }
262
254
263 void tst_qpieslice::mouseHover()
255 void tst_qpieslice::mouseHover()
264 {
256 {
265 // create a pie series
257 // create a pie series
266 QPieSeries *series = new QPieSeries();
258 QPieSeries *series = new QPieSeries();
267 series->setPieSize(1.0);
259 series->setPieSize(1.0);
268 QPieSlice *s1 = series->append("slice 1", 1);
260 QPieSlice *s1 = series->append("slice 1", 1);
269 series->append("slice 2", 2);
261 series->append("slice 2", 2);
270 series->append("slice 3", 3);
262 series->append("slice 3", 3);
271
263
272 // add series to the chart
264 // add series to the chart
273 QChartView view(new QChart());
265 QChartView view(new QChart());
274 view.chart()->legend()->setVisible(false);
266 view.chart()->legend()->setVisible(false);
275 view.resize(200, 200);
267 view.resize(200, 200);
276 view.chart()->addSeries(series);
268 view.chart()->addSeries(series);
277 view.show();
269 view.show();
278 QTest::qWaitForWindowShown(&view);
270 QTest::qWaitForWindowShown(&view);
279
271
280 // first move to right top corner
272 // first move to right top corner
281 QTest::mouseMove(view.viewport(), QPoint(200, 0));
273 QTest::mouseMove(view.viewport(), QPoint(200, 0));
282 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
274 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
283
275
284 // move inside slice rectangle but NOT the actual slice
276 // move inside slice rectangle but NOT the actual slice
285 // pie rectangle: QRectF(60,60 121x121)
277 // pie rectangle: QRectF(60,60 121x121)
286 QSignalSpy hoverSpy(s1, SIGNAL(hovered(bool)));
278 QSignalSpy hoverSpy(s1, SIGNAL(hovered(bool)));
287 QTest::mouseMove(view.viewport(), QPoint(170, 70));
279 QTest::mouseMove(view.viewport(), QPoint(170, 70));
288 TRY_COMPARE(hoverSpy.count(), 0);
280 TRY_COMPARE(hoverSpy.count(), 0);
289
281
290 // move inside the slice
282 // move inside the slice
291 QTest::mouseMove(view.viewport(), QPoint(139, 85));
283 QTest::mouseMove(view.viewport(), QPoint(139, 85));
292 TRY_COMPARE(hoverSpy.count(), 1);
284 TRY_COMPARE(hoverSpy.count(), 1);
293 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(0)), true);
285 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(0)), true);
294
286
295 // move outside the slice
287 // move outside the slice
296 QTest::mouseMove(view.viewport(), QPoint(200, 0));
288 QTest::mouseMove(view.viewport(), QPoint(200, 0));
297 TRY_COMPARE(hoverSpy.count(), 2);
289 TRY_COMPARE(hoverSpy.count(), 2);
298 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(0)), false);
290 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(0)), false);
299 }
291 }
300
292
301 QTEST_MAIN(tst_qpieslice)
293 QTEST_MAIN(tst_qpieslice)
302
294
303 #include "tst_qpieslice.moc"
295 #include "tst_qpieslice.moc"
304
296
@@ -1,168 +1,164
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 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 Flow {
24 Flow {
25 id: flow
25 id: flow
26 spacing: 5
26 spacing: 5
27 flow: Flow.TopToBottom
27 flow: Flow.TopToBottom
28 property variant series
28 property variant series
29
29
30 onSeriesChanged: {
30 onSeriesChanged: {
31 if (series && series.name == "pie") {
31 if (series && series.name == "pie") {
32 seriesConnections.target = series;
32 seriesConnections.target = series;
33 sliceConnections.target = series.at(0);
33 sliceConnections.target = series.at(0);
34 } else {
34 } else {
35 seriesConnections.target = null;
35 seriesConnections.target = null;
36 sliceConnections.target = null;
36 sliceConnections.target = null;
37 }
37 }
38 }
38 }
39
39
40 Connections {
40 Connections {
41 id: seriesConnections
41 id: seriesConnections
42 target: null
42 target: null
43 onVisibleChanged: console.log("series.onVisibleChanged: " + series.visible);
43 onVisibleChanged: console.log("series.onVisibleChanged: " + series.visible);
44 onCountChanged: console.log("series.onCountChanged: " + series.count);
44 onCountChanged: console.log("series.onCountChanged: " + series.count);
45 onSumChanged: console.log("series.onSumChanged: " + series.sum);
45 onSumChanged: console.log("series.onSumChanged: " + series.sum);
46 }
46 }
47
47
48 Connections {
48 Connections {
49 id: sliceConnections
49 id: sliceConnections
50 target: null
50 target: null
51 onValueChanged: console.log("slice.onValueChanged: " + series.at(0).value);
51 onValueChanged: console.log("slice.onValueChanged: " + series.at(0).value);
52 onLabelVisibleChanged: console.log("slice.onLabelVisibleChanged: " + series.at(0).labelVisible);
52 onLabelVisibleChanged: console.log("slice.onLabelVisibleChanged: " + series.at(0).labelVisible);
53 onLabelPositionChanged: console.log("slice.onLabelPositionChanged: " + series.at(0).labelPosition);
54 onExplodedChanged: console.log("slice.onExplodedChanged: " + series.at(0).exploded);
55 onPenChanged: console.log("slice.onPenChanged: " + series.at(0).pen);
53 onPenChanged: console.log("slice.onPenChanged: " + series.at(0).pen);
56 onBorderColorChanged: console.log("slice.onBorderColorChanged: " + series.at(0).borderColor);
54 onBorderColorChanged: console.log("slice.onBorderColorChanged: " + series.at(0).borderColor);
57 onBorderWidthChanged: console.log("slice.onBorderWidthChanged: " + series.at(0).borderWidth);
55 onBorderWidthChanged: console.log("slice.onBorderWidthChanged: " + series.at(0).borderWidth);
58 onBrushChanged: console.log("slice.onBrushChanged: " + series.at(0).brush);
56 onBrushChanged: console.log("slice.onBrushChanged: " + series.at(0).brush);
59 onColorChanged: console.log("slice.onColorChanged: " + series.at(0).color);
57 onColorChanged: console.log("slice.onColorChanged: " + series.at(0).color);
60 onLabelColorChanged: console.log("slice.onLabelColorChanged: " + series.at(0).labelColor);
58 onLabelColorChanged: console.log("slice.onLabelColorChanged: " + series.at(0).labelColor);
61 onLabelBrushChanged: console.log("slice.onLabelBrushChanged: " + series.at(0).labelBrush);
59 onLabelBrushChanged: console.log("slice.onLabelBrushChanged: " + series.at(0).labelBrush);
62 onLabelFontChanged: console.log("slice.onLabelFontChanged: " + series.at(0).labelFont);
60 onLabelFontChanged: console.log("slice.onLabelFontChanged: " + series.at(0).labelFont);
63 onLabelArmLengthFactorChanged: console.log("slice.onLabelArmLengthFactorChanged: " + series.at(0).labelArmLengthFactor);
64 onExplodeDistanceFactorChanged: console.log("slice.onExplodeDistanceFactorChanged: " + series.at(0).explodeDistanceFactor);
65 onPercentageChanged: console.log("slice.onPercentageChanged: " + series.at(0).percentage);
61 onPercentageChanged: console.log("slice.onPercentageChanged: " + series.at(0).percentage);
66 onStartAngleChanged: console.log("slice.onStartAngleChanged: " + series.at(0).startAngle);
62 onStartAngleChanged: console.log("slice.onStartAngleChanged: " + series.at(0).startAngle);
67 onAngleSpanChanged: console.log("slice.onAngleSpanChanged: " + series.at(0).angleSpan);
63 onAngleSpanChanged: console.log("slice.onAngleSpanChanged: " + series.at(0).angleSpan);
68 onClicked: console.log("slice.onClicked");
64 onClicked: console.log("slice.onClicked");
69 onHovered: console.log("slice.onHovered: " + state);
65 onHovered: console.log("slice.onHovered: " + state);
70 }
66 }
71
67
72 Button {
68 Button {
73 text: "visible"
69 text: "visible"
74 onClicked: series.visible = !series.visible;
70 onClicked: series.visible = !series.visible;
75 }
71 }
76 Button {
72 Button {
77 text: "series hpos +"
73 text: "series hpos +"
78 onClicked: series.horizontalPosition += 0.1;
74 onClicked: series.horizontalPosition += 0.1;
79 }
75 }
80 Button {
76 Button {
81 text: "series hpos -"
77 text: "series hpos -"
82 onClicked: series.horizontalPosition -= 0.1;
78 onClicked: series.horizontalPosition -= 0.1;
83 }
79 }
84 Button {
80 Button {
85 text: "series vpos +"
81 text: "series vpos +"
86 onClicked: series.verticalPosition += 0.1;
82 onClicked: series.verticalPosition += 0.1;
87 }
83 }
88 Button {
84 Button {
89 text: "series vpos -"
85 text: "series vpos -"
90 onClicked: series.verticalPosition -= 0.1;
86 onClicked: series.verticalPosition -= 0.1;
91 }
87 }
92 Button {
88 Button {
93 text: "series size +"
89 text: "series size +"
94 onClicked: series.size += 0.1;
90 onClicked: series.size += 0.1;
95 }
91 }
96 Button {
92 Button {
97 text: "series size -"
93 text: "series size -"
98 onClicked: series.size -= 0.1;
94 onClicked: series.size -= 0.1;
99 }
95 }
100 Button {
96 Button {
101 text: "series start angle +"
97 text: "series start angle +"
102 onClicked: series.startAngle += 1.1;
98 onClicked: series.startAngle += 1.1;
103 }
99 }
104 Button {
100 Button {
105 text: "series start angle -"
101 text: "series start angle -"
106 onClicked: series.startAngle -= 1.1;
102 onClicked: series.startAngle -= 1.1;
107 }
103 }
108 Button {
104 Button {
109 text: "series end angle +"
105 text: "series end angle +"
110 onClicked: series.endAngle += 1.1;
106 onClicked: series.endAngle += 1.1;
111 }
107 }
112 Button {
108 Button {
113 text: "series end angle -"
109 text: "series end angle -"
114 onClicked: series.endAngle -= 1.1;
110 onClicked: series.endAngle -= 1.1;
115 }
111 }
116 Button {
112 Button {
117 text: "slice color"
113 text: "slice color"
118 onClicked: series.at(0).color = main.nextColor();
114 onClicked: series.at(0).color = main.nextColor();
119 }
115 }
120 Button {
116 Button {
121 text: "slice border color"
117 text: "slice border color"
122 onClicked: series.at(0).borderColor = main.nextColor();
118 onClicked: series.at(0).borderColor = main.nextColor();
123 }
119 }
124 Button {
120 Button {
125 text: "slice border width +"
121 text: "slice border width +"
126 onClicked: series.at(0).borderWidth++;
122 onClicked: series.at(0).borderWidth++;
127 }
123 }
128 Button {
124 Button {
129 text: "slice border width -"
125 text: "slice border width -"
130 onClicked: series.at(0).borderWidth--;
126 onClicked: series.at(0).borderWidth--;
131 }
127 }
132 Button {
128 Button {
133 text: "slice label visible"
129 text: "slice label visible"
134 onClicked: series.at(0).labelVisible = !series.at(0).labelVisible;
130 onClicked: series.at(0).labelVisible = !series.at(0).labelVisible;
135 }
131 }
136 Button {
132 Button {
137 text: "slice label position inside"
133 text: "slice label position inside"
138 onClicked: series.at(0).labelPosition = PieSlice.LabelInside;
134 onClicked: series.at(0).labelPosition = PieSlice.LabelInside;
139 }
135 }
140 Button {
136 Button {
141 text: "slice label position outside"
137 text: "slice label position outside"
142 onClicked: series.at(0).labelPosition = PieSlice.LabelOutside;
138 onClicked: series.at(0).labelPosition = PieSlice.LabelOutside;
143 }
139 }
144 Button {
140 Button {
145 text: "slice label arm len +"
141 text: "slice label arm len +"
146 onClicked: series.at(0).labelArmLengthFactor += 0.1;
142 onClicked: series.at(0).labelArmLengthFactor += 0.1;
147 }
143 }
148 Button {
144 Button {
149 text: "slice label arm len -"
145 text: "slice label arm len -"
150 onClicked: series.at(0).labelArmLengthFactor -= 0.1;
146 onClicked: series.at(0).labelArmLengthFactor -= 0.1;
151 }
147 }
152 Button {
148 Button {
153 text: "slice label color"
149 text: "slice label color"
154 onClicked: series.at(0).labelColor = main.nextColor();
150 onClicked: series.at(0).labelColor = main.nextColor();
155 }
151 }
156 Button {
152 Button {
157 text: "slice exploded"
153 text: "slice exploded"
158 onClicked: series.at(0).exploded = !series.at(0).exploded;
154 onClicked: series.at(0).exploded = !series.at(0).exploded;
159 }
155 }
160 Button {
156 Button {
161 text: "slice explode dist +"
157 text: "slice explode dist +"
162 onClicked: series.at(0).explodeDistanceFactor += 0.1;
158 onClicked: series.at(0).explodeDistanceFactor += 0.1;
163 }
159 }
164 Button {
160 Button {
165 text: "slice explode dist -"
161 text: "slice explode dist -"
166 onClicked: series.at(0).explodeDistanceFactor -= 0.1;
162 onClicked: series.at(0).explodeDistanceFactor -= 0.1;
167 }
163 }
168 }
164 }
General Comments 0
You need to be logged in to leave comments. Login now