##// END OF EJS Templates
Removed unnecessary signals from QPieSlice
Tero Ahola -
r1494:0e4d11fde6b8
parent child
Show More
@@ -138,18 +138,20 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
138 138 PieSliceItem* sliceItem = new PieSliceItem(this);
139 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 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(slice, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged()));
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)));
@@ -186,6 +188,10 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
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);
@@ -140,17 +140,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
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 */
@@ -298,17 +287,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
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:
@@ -328,17 +306,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
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:
@@ -358,17 +325,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
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.
@@ -539,7 +495,7 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
@@ -552,7 +508,7 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
@@ -661,7 +617,7 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
@@ -674,7 +630,7 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
@@ -38,8 +38,8 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
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 NOTIFY labelPositionChanged)
42 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded NOTIFY explodedChanged)
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)
@@ -48,8 +48,8 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
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 NOTIFY labelArmLengthFactorChanged)
52 Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor NOTIFY explodeDistanceFactorChanged)
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)
@@ -117,17 +117,15 public:
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();
@@ -135,8 +133,6 Q_SIGNALS:
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;
@@ -56,6 +56,12 public:
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;
@@ -110,14 +110,10 void tst_qpieslice::changedSignals()
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()));
@@ -152,14 +148,10 void tst_qpieslice::changedSignals()
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);
@@ -50,8 +50,6 Flow {
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);
@@ -60,8 +58,6 Flow {
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);
General Comments 0
You need to be logged in to leave comments. Login now