##// END OF EJS Templates
Selectable outlines for box...
Mika Salmela -
r2573:3880b19e7795
parent child
Show More
@@ -25,6 +25,227
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 /*!
29 \qmlclass BoxSet QBoxSet
30
31 BoxSet represents one box-and-whiskers item. It takes five values to create a graphical representation
32 of range and three medians. There are two ways to give the values. The first one is with constructor
33 or with append method. In these the values have to be given in the following order: lower extreme, lower quartile, median,
34 upper quartile and upper extreme. The second method is to create an empty QBoxSet instance and give the values using
35 value specific methods.
36 \sa BoxPlotSeries
37 */
38 /*!
39 \qmlproperty string BoxSet::values
40 The values on the box-and-whiskers set.
41 */
42 /*!
43 \qmlproperty string BoxSet::label
44 Defines the label of the box-and-whiskers set.
45 */
46 /*!
47 \qmlproperty int BoxSet::count
48 The count of values on the box-and-whiskers set
49 */
50 /*!
51 \qmlmethod void BoxSet::at(int index)
52 Returns the value at \a index position.
53 */
54 /*!
55 \qmlmethod void BoxSet::append(qreal value)
56 Appends new value \a value to the end of set.
57 */
58 /*!
59 \qmlmethod void BoxSet::clear()
60 Sets all values on the set to 0.
61 */
62 /*!
63 \qmlmethod void BoxSet::setValue(int index, qreal value)
64 Sets a new \a value on the \a index position.
65 */
66 /*!
67 \qmlsignal BoxSet::onClicked()
68 This signal is emitted when the user clicks with a mouse on top of box-and-whiskers item.
69 */
70 /*!
71 \qmlsignal BoxSet::onHovered(bool status)
72 The signal is emitted if mouse is hovered on top of box-and-whiskers item.
73 Parameter \a status is true, if mouse entered on top of the item, and false if mouse left from top of the item.
74 */
75 /*!
76 \qmlsignal BoxSet::onPenChanged()
77 This signal is emitted when the pen of the box-and-whiskers item has changed.
78 */
79 /*!
80 \qmlsignal BoxSet::onBrushChanged()
81 This signal is emitted when the brush of the box-and-whiskers item has changed.
82 */
83 /*!
84 \qmlsignal BoxSet::onChangedValues()
85 This signal is emitted when multiple values have been changed on the box-and-whiskers item.
86 */
87 /*!
88 \qmlsignal BoxSet::onChangedValue(int index)
89 This signal is emitted values the value in the box-and-whiskers item has been modified.
90 Parameter \a index indicates the position of the modified value.
91 */
92 /*!
93 \qmlsignal BoxSet::onCleared()
94 This signal is emitted when all the values on the set are cleared to 0.
95 */
96
97
98 /*!
99 \qmlclass BoxPlotSeries QBoxPlotSeries
100 \inherits QAbstractSeries
101
102 BoxPlotSeries represents a series of data shown as box-and-whiskers bars. The purpose of this class is to act as
103 a container for single box-and-whiskers items. Each item is drawn to own slot. If chart includes multiple instances of
104 BoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot.
105
106 The following QML shows how to create a simple box-and-whiskers chart:
107 \code
108 import QtQuick 1.0
109 import QtCommercial.Chart 1.3
110
111 ChartView {
112 title: "Box Plot series"
113 width: 400
114 height: 300
115 theme: ChartView.ChartThemeBrownSand
116 legend.alignment: Qt.AlignBottom
117
118 BoxPlotSeries {
119 id: plotSeries
120 name: "Income"
121 BoxSet { label: "Jan"; values: [3, 4, 5.1, 6.2, 8.5] }
122 BoxSet { label: "Feb"; values: [5, 6, 7.5, 8.6, 11.8] }
123 BoxSet { label: "Mar"; values: [3.2, 5, 5.7, 8, 9.2] }
124 BoxSet { label: "Apr"; values: [3.8, 5, 6.4, 7, 8] }
125 BoxSet { label: "May"; values: [4, 5, 5.2, 6, 7] }
126 }
127 }
128 \endcode
129
130 \beginfloatleft
131 \image examples_qmlboxplot.png
132 \endfloat
133 \clearfloat
134 */
135 /*!
136 \qmlmethod BoxPlotSeries::append(string label, VariantList values)
137 Appends a new box-and-whiskers set with \a label and \a values to the series.
138 */
139 /*!
140 \qmlmethod BoxPlotSeries::append(BoxSet box)
141 Appends the \a box to the series.
142 */
143 /*!
144 \qmlmethod BoxPlotSeries::insert(int index, string label, VariantList values)
145 Inserts a new box-and-whiskers set with \a label and \a values at the \a index position.
146 */
147 /*!
148 \qmlmethod BoxPlotSeries::remove(QBoxSet boxset)
149 Removes the \a boxset from the series.
150 */
151 /*!
152 \qmlmethod BoxPlotSeries::clear()
153 Removes all boxsets from the series. Deletes removed sets.
154 */
155 /*!
156 \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset);
157 Signal is emitted when the user clicks the \a boxset on the chart.
158 */
159 /*!
160 \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset);
161 Signal is emitted when there is change in hover \a status over \a boxset.
162 */
163 /*!
164 \qmlsignal BoxPlotSeries::onCountChanged();
165 Signal is emitted when there is change in count of box-and-whiskers items in the series.
166 */
167 /*!
168 \qmlsignal BoxPlotSeries::onBoxsetsAdded()
169 Signal is emitted when new box-and-whiskers sets are added to the series.
170 */
171 /*!
172 \qmlsignal BoxPlotSeries::onBoxsetsRemoved()
173 Signal is emitted when new box-and-whiskers sets are removed from the series.
174 */
175 /*!
176 \qmlproperty AbstractAxis BoxPlotSeries::axisX
177 The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for
178 the series.
179 \sa axisXTop
180 */
181 /*!
182 \qmlproperty AbstractAxis BoxPlotSeries::axisY
183 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
184 the series.
185 \sa axisYRight
186 */
187 /*!
188 \qmlproperty AbstractAxis BoxPlotSeries::axisXTop
189 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
190 axisXTop, but not both.
191 \sa axisX
192 */
193 /*!
194 \qmlproperty AbstractAxis BoxPlotSeries::axisYRight
195 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
196 or axisYRight, but not both.
197 \sa axisY
198 */
199 /*!
200 \qmlproperty bool BoxPlotSeries::boxOutlineVisible
201 This property configures the visibility of the middle box outline.
202 */
203 /*!
204 \qmlproperty Pen BoxPlotSeries::pen
205 This property configures the pen of the box-and-whiskers items.
206 */
207 /*!
208 \qmlproperty Brush BoxPlotSeries::brush
209 This property configures the brush of the box-and-whiskers items.
210 */
211 /*!
212 \qmlsignal BoxPlotSeries::onBoxOutlineVisibilityChanged()
213 Signal is emitted when the middle box outline visibility is changed.
214 */
215 /*!
216 \qmlsignal BoxPlotSeries::onPenChanged()
217 Signal is emitted when the pen for box-and-whiskers items has changed.
218 */
219 /*!
220 \qmlsignal BoxPlotSeries::onBrushChanged()
221 Signal is emitted when the brush for box-and-whiskers items has changed.
222 */
223 /*!
224 \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset)
225 Signal is emitted when the user clicks the \a boxset on the chart.
226 */
227 /*!
228 \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset)
229 Signal is emitted when there is change in hover \a status over \a boxset.
230 */
231 /*!
232 \qmlsignal BoxPlotSeries::onAxisXChanged(AbstractAxis axis)
233 Signal is emitted when there is change in X axis.
234 */
235 /*!
236 \qmlsignal BoxPlotSeries::onAxisYChanged(AbstractAxis axis)
237 Signal is emitted when there is change in Y axis.
238 */
239 /*!
240 \qmlsignal BoxPlotSeries::onAxisXTopChanged(AbstractAxis axis)
241 Signal is emitted when there is change in top X axis.
242 */
243 /*!
244 \qmlsignal BoxPlotSeries::onAxisYRightChanged(AbstractAxis axis)
245 Signal is emitted when there is change in Y right axis.
246 */
247
248
28 249 DeclarativeBoxSet::DeclarativeBoxSet(const QString label, QObject *parent)
29 250 : QBoxSet(label, parent)
30 251 {
@@ -84,6 +84,7 void BoxPlotChartItem::handleDataStructureChanged()
84 84 // Set the decorative issues for the newly created box
85 85 box->setBrush(m_series->brush());
86 86 box->setPen(m_series->pen());
87 box->setBoxOutlined(m_series->boxOutlineVisible());
87 88 }
88 89 updateBoxGeometry(box, s);
89 90
@@ -101,6 +102,7 void BoxPlotChartItem::handleUpdatedBars()
101 102 foreach (BoxWhiskers *item, m_boxTable.values()) {
102 103 item->setBrush(m_series->brush());
103 104 item->setPen(m_series->pen());
105 item->setBoxOutlined(m_series->boxOutlineVisible());
104 106 }
105 107 // Override with QBoxSet specific settings
106 108 foreach (QBoxSet *set, m_boxTable.keys()) {
@@ -58,12 +58,22 void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
58 58 void BoxWhiskers::setBrush(const QBrush &brush)
59 59 {
60 60 m_brush = brush;
61 m_outlinePen.setColor(m_brush.color());
61 62 update();
62 63 }
63 64
64 65 void BoxWhiskers::setPen(const QPen &pen)
65 66 {
67 qreal widthDiff = pen.widthF() - m_pen.widthF();
68 m_boundingRect.adjust(-widthDiff, -widthDiff, widthDiff, widthDiff);
69
66 70 m_pen = pen;
71 m_medianPen = pen;
72 m_medianPen.setCapStyle(Qt::FlatCap);
73 m_outlinePen = pen;
74 m_outlinePen.setStyle(Qt::SolidLine);
75 m_outlinePen.setColor(m_brush.color());
76
67 77 update();
68 78 }
69 79
@@ -98,10 +108,17 void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
98 108 Q_UNUSED(option)
99 109 Q_UNUSED(widget)
100 110
101 painter->setPen(m_pen);
102 111 painter->setBrush(m_brush);
103 112 painter->setClipRect(parentItem()->boundingRect());
113 painter->setPen(m_pen);
104 114 painter->drawPath(m_boxPath);
115 if (!m_boxOutlined)
116 painter->setPen(m_outlinePen);
117 painter->drawRect(m_middleBox);
118 painter->setPen(m_medianPen);
119 qreal halfLine = m_pen.widthF() / 2.0;
120 painter->drawLine(QLineF(m_geometryLeft - halfLine, m_geometryMedian,
121 m_geometryRight + halfLine, m_geometryMedian));
105 122 }
106 123
107 124 void BoxWhiskers::updateGeometry(AbstractDomain *domain)
@@ -121,12 +138,12 void BoxWhiskers::updateGeometry(AbstractDomain *domain)
121 138 QPointF geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_upperExtreme), m_validData);
122 139 if (!m_validData)
123 140 return;
124 qreal geometryLeft = geometryPoint.x();
141 m_geometryLeft = geometryPoint.x();
125 142 qreal geometryUpperExtreme = geometryPoint.y();
126 143 geometryPoint = m_domain->calculateGeometryPoint(QPointF(left + barWidth, m_data.m_upperQuartile), m_validData);
127 144 if (!m_validData)
128 145 return;
129 qreal geometryRight = geometryPoint.x();
146 m_geometryRight = geometryPoint.x();
130 147 qreal geometryUpperQuartile = geometryPoint.y();
131 148 geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_lowerQuartile), m_validData);
132 149 if (!m_validData)
@@ -139,33 +156,29 void BoxWhiskers::updateGeometry(AbstractDomain *domain)
139 156 geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_median), m_validData);
140 157 if (!m_validData)
141 158 return;
142 qreal geometryMedian = geometryPoint.y();
159 m_geometryMedian = geometryPoint.y();
143 160
144 161 // Upper whisker
145 path.moveTo(geometryLeft, geometryUpperExtreme);
146 path.lineTo(geometryRight, geometryUpperExtreme);
147 path.moveTo((geometryLeft + geometryRight) / 2.0, geometryUpperExtreme);
148 path.lineTo((geometryLeft + geometryRight) / 2.0, geometryUpperQuartile);
162 path.moveTo(m_geometryLeft, geometryUpperExtreme);
163 path.lineTo(m_geometryRight, geometryUpperExtreme);
164 path.moveTo((m_geometryLeft + m_geometryRight) / 2.0, geometryUpperExtreme);
165 path.lineTo((m_geometryLeft + m_geometryRight) / 2.0, geometryUpperQuartile);
149 166
150 167 // Middle Box
151 path.addRect(geometryLeft, geometryUpperQuartile, geometryRight - geometryLeft, geometryLowerQuartile - geometryUpperQuartile);
152
153 // Median line
154 path.moveTo(geometryLeft, geometryMedian);
155 path.lineTo(geometryRight, geometryMedian);
168 m_middleBox.setCoords(m_geometryLeft, geometryUpperQuartile, m_geometryRight, geometryLowerQuartile);
156 169
157 170 // Lower whisker
158 path.moveTo(geometryLeft, geometryLowerExtreme);
159 path.lineTo(geometryRight, geometryLowerExtreme);
160 path.moveTo((geometryLeft + geometryRight) / 2.0, geometryLowerQuartile);
161 path.lineTo((geometryLeft + geometryRight) / 2.0, geometryLowerExtreme);
171 path.moveTo(m_geometryLeft, geometryLowerExtreme);
172 path.lineTo(m_geometryRight, geometryLowerExtreme);
173 path.moveTo((m_geometryLeft + m_geometryRight) / 2.0, geometryLowerQuartile);
174 path.lineTo((m_geometryLeft + m_geometryRight) / 2.0, geometryLowerExtreme);
162 175
163 176 path.closeSubpath();
164 177
165 178 m_boxPath = path;
166 179 m_boundingRect = m_boxPath.boundingRect();
167 180
168 qreal extra = (m_pen.width() / 2.0);
181 qreal extra = (m_pen.widthF() / 2.0);
169 182 m_boundingRect.adjust(-extra, -extra, extra, extra);
170 183 }
171 184
@@ -54,6 +54,7 public:
54 54 void setBrush(const QBrush &brush);
55 55 void setPen(const QPen &pen);
56 56 void setLayout(const BoxWhiskersData &data);
57 void setBoxOutlined(const bool outlined) { m_boxOutlined = outlined; }
57 58
58 59 void mousePressEvent(QGraphicsSceneMouseEvent *event);
59 60 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
@@ -83,8 +84,15 private:
83 84 bool m_validData;
84 85 QBrush m_brush;
85 86 QPen m_pen;
87 QPen m_medianPen;
88 QPen m_outlinePen;
89 bool m_boxOutlined;
86 90 BoxWhiskersData m_data;
87 91 QSizeF m_domainSize;
92 QRectF m_middleBox;
93 qreal m_geometryMedian;
94 qreal m_geometryLeft;
95 qreal m_geometryRight;
88 96 };
89 97
90 98 QTCOMMERCIALCHART_END_NAMESPACE
@@ -48,114 +48,58 QTCOMMERCIALCHART_BEGIN_NAMESPACE
48 48
49 49 \sa QBoxSet
50 50 */
51
52 /*!
53 \qmlclass BoxPlotSeries QBoxPlotSeries
54 \inherits QAbstractSeries
55
56 BoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as
57 a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple instances of
58 BoxPlotSeries then box-and-whiskers items with the same index are drawn to same slot.
59
60 The following QML shows how to create a simple box-and-whiskers chart:
61 \code
62 import QtQuick 1.0
63 import QtCommercial.Chart 1.1
64
65 ChartView {
66 title: "Box Plot series"
67 width: 400
68 height: 300
69 theme: ChartView.ChartThemeBrownSand
70 legend.alignment: Qt.AlignBottom
71
72 BoxPlotSeries {
73 id: plotSeries
74 name: "Income"
75 BoxSet { label: "Jan"; values: [3, 4, 5.1, 6.2, 8.5] }
76 BoxSet { label: "Feb"; values: [5, 6, 7.5, 8.6, 11.8] }
77 BoxSet { label: "Mar"; values: [3.2, 5, 5.7, 8, 9.2] }
78 BoxSet { label: "Apr"; values: [3.8, 5, 6.4, 7, 8] }
79 BoxSet { label: "May"; values: [4, 5, 5.2, 6, 7] }
80 }
81 }
82 \endcode
83
84 \beginfloatleft
85 \image examples_qmlboxplot.png
86 \endfloat
87 \clearfloat
88 */
89
90 51 /*!
91 52 \fn QBoxPlotSeries::boxsetsAdded(QList<QBoxSet *> sets)
92 53 \brief Signal is emitted when a new \a sets of box-and-whiskers data is added to the series.
93 54 */
94
95 55 /*!
96 56 \fn QBoxPlotSeries::boxsetsRemoved(QList<QBoxSet *> sets)
97 57 \brief Signal is emitted when \a sets of box-and-whiskers data is removed from the series.
98 58 */
99
100 59 /*!
101 60 \fn QBoxPlotSeries::clicked(QBoxSet *boxset)
102 61 \brief Signal is emitted when the user clicks the \a boxset on the chart.
103 62 */
104
105 63 /*!
106 64 \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset)
107 65 \brief Signal is emitted when there is change in hover \a status over \a boxset.
108 66 */
109
110 67 /*!
111 68 \fn QBoxPlotSeries::countChanged()
112 69 \brief Signal is emitted when there is change in count of box-and-whiskers items in the series.
113 70 */
114 71 /*!
115 \fn virtual SeriesType QBoxPlotSeries::type() const
116 \brief Returns type of series.
117 \sa QAbstractSeries, SeriesType
72 \property QBoxPlotSeries::boxOutlineVisible
73 \brief This property configures the visibility of the middle box outline.
118 74 */
119 75 /*!
120 \qmlmethod BoxPlotSeries::append(const QString label, QVariantList values)
121 Appends a new box-and-whiskers set with \a label and \a values to the series.
76 \property QBoxPlotSeries::pen
77 \brief This property configures the pen of the box-and-whiskers items.
122 78 */
123 79 /*!
124 \qmlmethod BoxPlotSeries::append(BoxSet *box)
125 Appends the \a box to the series.
80 \property QBoxPlotSeries::brush
81 \brief This property configures the brush of the box-and-whiskers items.
126 82 */
127 83 /*!
128 \qmlmethod BoxPlotSeries::insert(int index, const QString label, QVariantList values)
129 Inserts a new box-and-whiskers set with \a label and \a values at the \a index position.
84 \fn void QBoxPlotSeries::boxOutlineVisibilityChanged()
85 Signal is emitted when the middle box outline visibility is changed.
130 86 */
131 87 /*!
132 \qmlmethod BoxPlotSeries::remove(QBoxSet *boxset)
133 Removes the \a boxset from the series.
88 \fn void QBoxPlotSeries::penChanged()
89 This signal is emitted when the pen of the box-and-whiskers has changed.
90 \sa brush
134 91 */
135 92 /*!
136 \qmlmethod BoxPlotSeries::clear()
137 Removes all boxsets from the series. Deletes removed sets.
93 \fn void QBoxPlotSeries::brushChanged()
94 This signal is emitted when the brush of the box-and-whiskers has changed.
95 \sa brush
138 96 */
139 97
98
140 99 /*!
141 \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset);
142 Signal is emitted when the user clicks the \a boxset on the chart.
143 */
144 /*!
145 \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset);
146 Signal is emitted when there is change in hover \a status over \a boxset.
147 */
148 /*!
149 \qmlsignal BoxPlotSeries::onCountChanged();
150 Signal is emitted when there is change in count of box-and-whiskers items in the series.
151 */
152 /*!
153 \qmlsignal BoxPlotSeries::onBoxsetsAdded()
154 Signal is emitted when new box-and-whiskers sets are added to the series.
155 */
156 /*!
157 \qmlsignal BoxPlotSeries::boxsetsRemoved()
158 Signal is emitted when new box-and-whiskers sets are removed from the series.
100 \fn virtual SeriesType QBoxPlotSeries::type() const
101 \brief Returns type of series.
102 \sa QAbstractSeries, SeriesType
159 103 */
160 104
161 105 /*!
@@ -314,9 +258,24 QAbstractSeries::SeriesType QBoxPlotSeries::type() const
314 258 return QAbstractSeries::SeriesTypeBoxPlot;
315 259 }
316 260
317 /*!
318 Sets brush for the series. Box-and-whiskers items are drawn using \a brush
319 */
261 void QBoxPlotSeries::setBoxOutlineVisible(bool visible)
262 {
263 Q_D(QBoxPlotSeries);
264
265 if (d->m_boxOutlineVisible != visible) {
266 d->m_boxOutlineVisible = visible;
267 emit d->updated();
268 emit boxOutlineVisibilityChanged();
269 }
270 }
271
272 bool QBoxPlotSeries::boxOutlineVisible()
273 {
274 Q_D(QBoxPlotSeries);
275
276 return d->m_boxOutlineVisible;
277 }
278
320 279 void QBoxPlotSeries::setBrush(const QBrush &brush)
321 280 {
322 281 Q_D(QBoxPlotSeries);
@@ -324,12 +283,10 void QBoxPlotSeries::setBrush(const QBrush &brush)
324 283 if (d->m_brush != brush) {
325 284 d->m_brush = brush;
326 285 emit d->updated();
286 emit brushChanged();
327 287 }
328 288 }
329 289
330 /*!
331 Returns brush of the series.
332 */
333 290 QBrush QBoxPlotSeries::brush() const
334 291 {
335 292 Q_D(const QBoxPlotSeries);
@@ -337,9 +294,6 QBrush QBoxPlotSeries::brush() const
337 294 return d->m_brush;
338 295 }
339 296
340 /*!
341 Sets pen for the series. Box-and-whiskers items are drawn using \a pen
342 */
343 297 void QBoxPlotSeries::setPen(const QPen &pen)
344 298 {
345 299 Q_D(QBoxPlotSeries);
@@ -347,12 +301,10 void QBoxPlotSeries::setPen(const QPen &pen)
347 301 if (d->m_pen != pen) {
348 302 d->m_pen = pen;
349 303 emit d->updated();
304 emit penChanged();
350 305 }
351 306 }
352 307
353 /*!
354 Returns the pen of this series.
355 */
356 308 QPen QBoxPlotSeries::pen() const
357 309 {
358 310 Q_D(const QBoxPlotSeries);
@@ -365,7 +317,8 QPen QBoxPlotSeries::pen() const
365 317 QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q)
366 318 : QAbstractSeriesPrivate(q),
367 319 m_pen(QChartPrivate::defaultPen()),
368 m_brush(QChartPrivate::defaultBrush())
320 m_brush(QChartPrivate::defaultBrush()),
321 m_boxOutlineVisible(true)
369 322 {
370 323 }
371 324
@@ -32,6 +32,9 class QBoxPlotSeriesPrivate;
32 32 class QTCOMMERCIALCHART_EXPORT QBoxPlotSeries : public QAbstractSeries
33 33 {
34 34 Q_OBJECT
35 Q_PROPERTY(bool boxOutlineVisible READ boxOutlineVisible WRITE setBoxOutlineVisible NOTIFY boxOutlineVisibilityChanged)
36 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
37 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
35 38 public:
36 39 explicit QBoxPlotSeries(QObject *parent = 0);
37 40 ~QBoxPlotSeries();
@@ -47,6 +50,8 public:
47 50
48 51 QAbstractSeries::SeriesType type() const;
49 52
53 void setBoxOutlineVisible(bool visible);
54 bool boxOutlineVisible();
50 55 void setBrush(const QBrush &brush);
51 56 QBrush brush() const;
52 57 void setPen(const QPen &pen);
@@ -56,6 +61,9 Q_SIGNALS:
56 61 void clicked(QBoxSet *boxset);
57 62 void hovered(bool status, QBoxSet *boxset);
58 63 void countChanged();
64 void penChanged();
65 void brushChanged();
66 void boxOutlineVisibilityChanged();
59 67
60 68 void boxsetsAdded(QList<QBoxSet *> sets);
61 69 void boxsetsRemoved(QList<QBoxSet *> sets);
@@ -86,6 +86,7 protected:
86 86 QList<QBoxSet *> m_boxSets;
87 87 QPen m_pen;
88 88 QBrush m_brush;
89 bool m_boxOutlineVisible;
89 90 int m_index;
90 91 BoxPlotAnimation *m_animation;
91 92
@@ -39,16 +39,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39 \sa QBoxPlotSeries
40 40 */
41 41 /*!
42 \qmlclass BoxSet QBoxSet
43
44 BoxSet represents one box-and-whiskers item. It takes five values to create a graphical representation
45 of range and three medians. There are two ways to give the values. The first one is with constructor
46 or with append method. In these the values have to be given in the following order: lower extreme, lower quartile, median,
47 upper quartile and upper extre. The second method is to create an empty QBoxSet instance and give the values using
48 value specific methods.
49 \sa BoxPlotSeries
50 */
51 /*!
52 42 \enum QBoxSet::ValuePositions
53 43
54 44 \value LowerExtreme
@@ -57,102 +47,49 QTCOMMERCIALCHART_BEGIN_NAMESPACE
57 47 \value UpperQuartile
58 48 \value UpperExtreme
59 49 */
60
61 /*!
62 \qmlproperty string BoxSet::label
63 Defines the label of the boxSet.
64 */
65 /*!
66 \qmlproperty int BoxSet::count
67 The count of values on the box-and-whiskers set
68 */
69
70 50 /*!
71 51 \property QBoxSet::pen
72 52 \brief Defines the pen used by the box-and-whiskers set.
73 53 */
74
75 54 /*!
76 55 \property QBoxSet::brush
77 56 \brief Defines the brush used by the box-and-whiskers set.
78 57 */
79
80 /*!
81 \qmlmethod void BoxSet::setValue(int index, qreal value)
82 Sets a new \a value on the \a index position.
83 */
84 58 /*!
85 59 \fn void QBoxSet::clicked()
86 60 The signal is emitted if the user clicks with a mouse on top of box-and-whisker item.
87 61 */
88 62 /*!
89 \qmlsignal BoxSet::onClicked()
90 This signal is emitted when the user clicks with a mouse on top of box-and-whisker item.
91 */
92
93 /*!
94 63 \fn void QBoxSet::hovered(bool status)
95 64
96 65 The signal is emitted if mouse is hovered on top of box-and-whisker item.
97 66 Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item.
98 67 */
99 68 /*!
100 \qmlsignal BoxSet::onHovered(bool status)
101
102 The signal is emitted if mouse is hovered on top of box-and-whisker item.
103 Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item.
104 */
105
106 /*!
107 69 \fn void QBoxSet::penChanged()
108 70 This signal is emitted when the pen of the box-and-whisker item has changed.
109 71 \sa pen
110 72 */
111 73 /*!
112 \qmlsignal BoxSet::onPenChanged()
113 This signal is emitted when the pen of the box-and-whisker item has changed.
114 */
115 /*!
116 74 \fn void QBoxSet::brushChanged()
117 75 This signal is emitted when the brush of the box-and-whisker item has changed.
118 76 \sa brush
119 77 */
120 78 /*!
121 \qmlsignal BoxSet::onBrushChanged()
122 This signal is emitted when the brush of the box-and-whisker item has changed.
123 */
124
125 /*!
126 79 \fn void QBoxSet::valuesChanged()
127 80 This signal is emitted when multiple values have been changed on the box-and-whisker item.
128 81 \sa append()
129 82 */
130 83 /*!
131 \qmlsignal BoxSet::onChangedValues()
132 This signal is emitted when multiple values have been changed on the box-and-whisker item.
133 */
134
135 /*!
136 84 \fn void QBoxSet::valueChanged(int index)
137 85 This signal is emitted values the value in the box-and-whisker item has been modified.
138 86 Parameter \a index indicates the position of the modified value.
139 87 \sa at()
140 88 */
141 89 /*!
142 \qmlsignal BoxSet::onChangedValue(int index)
143 This signal is emitted values the value in the box-and-whisker item has been modified.
144 Parameter \a index indicates the position of the modified value.
145 */
146
147 /*!
148 90 \fn void QBoxSet::cleared()
149 91 This signal is emitted when all the values on the set are cleared to 0.
150 92 */
151 /*!
152 \qmlsignal BoxSet::onCleared()
153 This signal is emitted when all the values on the set are cleared to 0.
154 */
155
156 93
157 94 /*!
158 95 Constructs QBoxSet with optional \a label and parent of \a parent
@@ -193,6 +193,10 void MainWidget::initCheckboxes(QGridLayout *grid)
193 193 modelMapperCheckBox->setChecked(false);
194 194 grid->addWidget(modelMapperCheckBox, m_rowPos++, 0);
195 195
196 m_boxOutlined = new QCheckBox("Box outlined");
197 connect(m_boxOutlined, SIGNAL(toggled(bool)), this, SLOT(boxOutlineToggled(bool)));
198 m_boxOutlined->setChecked(true);
199 grid->addWidget(m_boxOutlined, m_rowPos++, 0);
196 200 }
197 201
198 202 void MainWidget::updateAxis(int categoryCount)
@@ -244,6 +248,8 void MainWidget::addSeries()
244 248 connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked()));
245 249 connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool)));
246 250
251 m_series[m_seriesCount]->setBoxOutlineVisible(m_boxOutlined->checkState());
252
247 253 m_chart->addSeries(m_series[m_seriesCount]);
248 254
249 255 updateAxis(m_series[0]->count());
@@ -383,6 +389,13 void MainWidget::antialiasingToggled(bool enabled)
383 389 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
384 390 }
385 391
392 void MainWidget::boxOutlineToggled(bool visible)
393 {
394 qDebug() << "BoxPlotTester::boxOutlineToggled toggled to " << visible;
395 for (int i = 0; i < m_seriesCount; i++)
396 m_series[i]->setBoxOutlineVisible(visible);
397 }
398
386 399 void MainWidget::modelMapperToggled(bool enabled)
387 400 {
388 401 if (enabled) {
@@ -445,5 +458,4 void MainWidget::changePen()
445 458 qDebug() << "changePen() = " << m_penTool->pen();
446 459 for (int i = 0; i < m_seriesCount; i++)
447 460 m_series[i]->setPen(m_penTool->pen());
448
449 461 }
@@ -30,6 +30,7
30 30 #include <QBoxPlotSeries>
31 31 #include <QBarCategoryAxis>
32 32 #include <QBoxSet>
33 #include <QCheckBox>
33 34
34 35 class QGridLayout;
35 36
@@ -68,6 +69,7 private slots:
68 69 void singleBoxHovered(bool state);
69 70 void changePen();
70 71 void antialiasingToggled(bool);
72 void boxOutlineToggled(bool);
71 73
72 74 private:
73 75 QChart *m_chart;
@@ -79,6 +81,7 private:
79 81 int m_rowPos;
80 82 int m_seriesCount;
81 83 QBoxPlotSeries *m_series[10];
84 QCheckBox *m_boxOutlined;
82 85 };
83 86
84 87 #endif // MAINWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now