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