@@ -201,6 +201,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
201 | This property configures the visibility of the middle box outline. |
|
201 | This property configures the visibility of the middle box outline. | |
202 | */ |
|
202 | */ | |
203 | /*! |
|
203 | /*! | |
|
204 | \qmlproperty qreal BoxPlotSeries::boxWidth | |||
|
205 | This property configures the width of the box-and-whiskers item. The value signifies the relative | |||
|
206 | width of the box-and-whiskers item inside its own slot. The value can between 0.0 and 1.0. Negative values | |||
|
207 | are clamped to 0.0 and values over 1.0 are clamped to 1.0. | |||
|
208 | */ | |||
|
209 | /*! | |||
204 | \qmlproperty Pen BoxPlotSeries::pen |
|
210 | \qmlproperty Pen BoxPlotSeries::pen | |
205 | This property configures the pen of the box-and-whiskers items. |
|
211 | This property configures the pen of the box-and-whiskers items. | |
206 | */ |
|
212 | */ | |
@@ -213,6 +219,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
213 | Signal is emitted when the middle box outline visibility is changed. |
|
219 | Signal is emitted when the middle box outline visibility is changed. | |
214 | */ |
|
220 | */ | |
215 | /*! |
|
221 | /*! | |
|
222 | \qmlsignal BoxPlotSeries::onBoxWidthChanged() | |||
|
223 | Signal is emitted when the width of the box-and-whiskers item is changed. | |||
|
224 | */ | |||
|
225 | /*! | |||
216 | \qmlsignal BoxPlotSeries::onPenChanged() |
|
226 | \qmlsignal BoxPlotSeries::onPenChanged() | |
217 | Signal is emitted when the pen for box-and-whiskers items has changed. |
|
227 | Signal is emitted when the pen for box-and-whiskers items has changed. | |
218 | */ |
|
228 | */ |
@@ -85,6 +85,7 void BoxPlotChartItem::handleDataStructureChanged() | |||||
85 | box->setBrush(m_series->brush()); |
|
85 | box->setBrush(m_series->brush()); | |
86 | box->setPen(m_series->pen()); |
|
86 | box->setPen(m_series->pen()); | |
87 | box->setBoxOutlined(m_series->boxOutlineVisible()); |
|
87 | box->setBoxOutlined(m_series->boxOutlineVisible()); | |
|
88 | box->setBoxWidth(m_series->boxWidth()); | |||
88 | } |
|
89 | } | |
89 | updateBoxGeometry(box, s); |
|
90 | updateBoxGeometry(box, s); | |
90 |
|
91 | |||
@@ -103,6 +104,7 void BoxPlotChartItem::handleUpdatedBars() | |||||
103 | item->setBrush(m_series->brush()); |
|
104 | item->setBrush(m_series->brush()); | |
104 | item->setPen(m_series->pen()); |
|
105 | item->setPen(m_series->pen()); | |
105 | item->setBoxOutlined(m_series->boxOutlineVisible()); |
|
106 | item->setBoxOutlined(m_series->boxOutlineVisible()); | |
|
107 | item->setBoxWidth(m_series->boxWidth()); | |||
106 | } |
|
108 | } | |
107 | // Override with QBoxSet specific settings |
|
109 | // Override with QBoxSet specific settings | |
108 | foreach (QBoxSet *set, m_boxTable.keys()) { |
|
110 | foreach (QBoxSet *set, m_boxTable.keys()) { | |
@@ -146,6 +148,8 void BoxPlotChartItem::handleLayoutChanged() | |||||
146 | if (m_animation) |
|
148 | if (m_animation) | |
147 | m_animation->setAnimationStart(item); |
|
149 | m_animation->setAnimationStart(item); | |
148 |
|
150 | |||
|
151 | item->setBoxWidth(m_series->boxWidth()); | |||
|
152 | ||||
149 | bool dirty = updateBoxGeometry(item, item->m_data.m_index); |
|
153 | bool dirty = updateBoxGeometry(item, item->m_data.m_index); | |
150 | if (dirty && m_animation) |
|
154 | if (dirty && m_animation) | |
151 | presenter()->startAnimation(m_animation->boxChangeAnimation(item)); |
|
155 | presenter()->startAnimation(m_animation->boxChangeAnimation(item)); |
@@ -77,6 +77,11 void BoxWhiskers::setPen(const QPen &pen) | |||||
77 | update(); |
|
77 | update(); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
|
80 | void BoxWhiskers::setBoxWidth(const qreal width) | |||
|
81 | { | |||
|
82 | m_boxWidth = width; | |||
|
83 | } | |||
|
84 | ||||
80 | void BoxWhiskers::setLayout(const BoxWhiskersData &data) |
|
85 | void BoxWhiskers::setLayout(const BoxWhiskersData &data) | |
81 | { |
|
86 | { | |
82 | m_data = data; |
|
87 | m_data = data; | |
@@ -132,8 +137,8 void BoxWhiskers::updateGeometry(AbstractDomain *domain) | |||||
132 | m_boundingRect = m_boxPath.boundingRect(); |
|
137 | m_boundingRect = m_boxPath.boundingRect(); | |
133 |
|
138 | |||
134 | qreal columnWidth = 1.0 / m_data.m_seriesCount; |
|
139 | qreal columnWidth = 1.0 / m_data.m_seriesCount; | |
135 |
qreal left = |
|
140 | qreal left = ((1.0 - m_boxWidth) / 2.0) * columnWidth + columnWidth * m_data.m_seriesIndex + m_data.m_index - 0.5; | |
136 |
qreal barWidth = columnWidth |
|
141 | qreal barWidth = m_boxWidth * columnWidth; | |
137 |
|
142 | |||
138 | QPointF geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_upperExtreme), m_validData); |
|
143 | QPointF geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_upperExtreme), m_validData); | |
139 | if (!m_validData) |
|
144 | if (!m_validData) | |
@@ -178,7 +183,7 void BoxWhiskers::updateGeometry(AbstractDomain *domain) | |||||
178 | m_boxPath = path; |
|
183 | m_boxPath = path; | |
179 | m_boundingRect = m_boxPath.boundingRect(); |
|
184 | m_boundingRect = m_boxPath.boundingRect(); | |
180 |
|
185 | |||
181 |
qreal extra = |
|
186 | qreal extra = m_pen.widthF(); | |
182 | m_boundingRect.adjust(-extra, -extra, extra, extra); |
|
187 | m_boundingRect.adjust(-extra, -extra, extra, extra); | |
183 | } |
|
188 | } | |
184 |
|
189 |
@@ -55,6 +55,7 public: | |||||
55 | void setPen(const QPen &pen); |
|
55 | void setPen(const QPen &pen); | |
56 | void setLayout(const BoxWhiskersData &data); |
|
56 | void setLayout(const BoxWhiskersData &data); | |
57 | void setBoxOutlined(const bool outlined) { m_boxOutlined = outlined; } |
|
57 | void setBoxOutlined(const bool outlined) { m_boxOutlined = outlined; } | |
|
58 | void setBoxWidth(const qreal width); | |||
58 |
|
59 | |||
59 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
60 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
60 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
|
61 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
@@ -87,6 +88,7 private: | |||||
87 | QPen m_medianPen; |
|
88 | QPen m_medianPen; | |
88 | QPen m_outlinePen; |
|
89 | QPen m_outlinePen; | |
89 | bool m_boxOutlined; |
|
90 | bool m_boxOutlined; | |
|
91 | qreal m_boxWidth; | |||
90 | BoxWhiskersData m_data; |
|
92 | BoxWhiskersData m_data; | |
91 | QSizeF m_domainSize; |
|
93 | QSizeF m_domainSize; | |
92 | QRectF m_middleBox; |
|
94 | QRectF m_middleBox; |
@@ -73,6 +73,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
73 | \brief This property configures the visibility of the middle box outline. |
|
73 | \brief This property configures the visibility of the middle box outline. | |
74 | */ |
|
74 | */ | |
75 | /*! |
|
75 | /*! | |
|
76 | \property QBoxPlotSeries::boxWidth | |||
|
77 | \brief This property configures the width of the box-and-whiskers item. The value signifies the relative | |||
|
78 | width of the box-and-whiskers item inside its own slot. The value can between 0.0 and 1.0. Negative values | |||
|
79 | are clamped to 0.0 and values over 1.0 are clamped to 1.0. | |||
|
80 | */ | |||
|
81 | /*! | |||
76 | \property QBoxPlotSeries::pen |
|
82 | \property QBoxPlotSeries::pen | |
77 | \brief This property configures the pen of the box-and-whiskers items. |
|
83 | \brief This property configures the pen of the box-and-whiskers items. | |
78 | */ |
|
84 | */ | |
@@ -85,6 +91,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
85 | Signal is emitted when the middle box outline visibility is changed. |
|
91 | Signal is emitted when the middle box outline visibility is changed. | |
86 | */ |
|
92 | */ | |
87 | /*! |
|
93 | /*! | |
|
94 | \fn void QBoxPlotSeries::boxWidthChanged() | |||
|
95 | Signal is emitted when the width of the box-and-whiskers item is changed. | |||
|
96 | */ | |||
|
97 | /*! | |||
88 | \fn void QBoxPlotSeries::penChanged() |
|
98 | \fn void QBoxPlotSeries::penChanged() | |
89 | This signal is emitted when the pen of the box-and-whiskers has changed. |
|
99 | This signal is emitted when the pen of the box-and-whiskers has changed. | |
90 | \sa brush |
|
100 | \sa brush | |
@@ -94,8 +104,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
94 | This signal is emitted when the brush of the box-and-whiskers has changed. |
|
104 | This signal is emitted when the brush of the box-and-whiskers has changed. | |
95 | \sa brush |
|
105 | \sa brush | |
96 | */ |
|
106 | */ | |
97 |
|
||||
98 |
|
||||
99 | /*! |
|
107 | /*! | |
100 | \fn virtual SeriesType QBoxPlotSeries::type() const |
|
108 | \fn virtual SeriesType QBoxPlotSeries::type() const | |
101 | \brief Returns type of series. |
|
109 | \brief Returns type of series. | |
@@ -276,6 +284,28 bool QBoxPlotSeries::boxOutlineVisible() | |||||
276 | return d->m_boxOutlineVisible; |
|
284 | return d->m_boxOutlineVisible; | |
277 | } |
|
285 | } | |
278 |
|
286 | |||
|
287 | void QBoxPlotSeries::setBoxWidth(qreal width) | |||
|
288 | { | |||
|
289 | Q_D(QBoxPlotSeries); | |||
|
290 | ||||
|
291 | if (width != d->m_boxWidth) { | |||
|
292 | if (width < 0.0) | |||
|
293 | width = 0.0; | |||
|
294 | if (width > 1.0) | |||
|
295 | width = 1.0; | |||
|
296 | d->m_boxWidth = width; | |||
|
297 | emit d->updatedLayout(); | |||
|
298 | emit boxWidthChanged(); | |||
|
299 | } | |||
|
300 | } | |||
|
301 | ||||
|
302 | qreal QBoxPlotSeries::boxWidth() | |||
|
303 | { | |||
|
304 | Q_D(QBoxPlotSeries); | |||
|
305 | ||||
|
306 | return d->m_boxWidth; | |||
|
307 | } | |||
|
308 | ||||
279 | void QBoxPlotSeries::setBrush(const QBrush &brush) |
|
309 | void QBoxPlotSeries::setBrush(const QBrush &brush) | |
280 | { |
|
310 | { | |
281 | Q_D(QBoxPlotSeries); |
|
311 | Q_D(QBoxPlotSeries); | |
@@ -318,7 +348,8 QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q) | |||||
318 | : QAbstractSeriesPrivate(q), |
|
348 | : QAbstractSeriesPrivate(q), | |
319 | m_pen(QChartPrivate::defaultPen()), |
|
349 | m_pen(QChartPrivate::defaultPen()), | |
320 | m_brush(QChartPrivate::defaultBrush()), |
|
350 | m_brush(QChartPrivate::defaultBrush()), | |
321 | m_boxOutlineVisible(true) |
|
351 | m_boxOutlineVisible(true), | |
|
352 | m_boxWidth(0.5) | |||
322 | { |
|
353 | { | |
323 | } |
|
354 | } | |
324 |
|
355 |
@@ -33,6 +33,7 class QTCOMMERCIALCHART_EXPORT QBoxPlotSeries : public QAbstractSeries | |||||
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | Q_PROPERTY(bool boxOutlineVisible READ boxOutlineVisible WRITE setBoxOutlineVisible NOTIFY boxOutlineVisibilityChanged) |
|
35 | Q_PROPERTY(bool boxOutlineVisible READ boxOutlineVisible WRITE setBoxOutlineVisible NOTIFY boxOutlineVisibilityChanged) | |
|
36 | Q_PROPERTY(qreal boxWidth READ boxWidth WRITE setBoxWidth NOTIFY boxWidthChanged) | |||
36 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) |
|
37 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) | |
37 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) |
|
38 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) | |
38 | public: |
|
39 | public: | |
@@ -52,6 +53,8 public: | |||||
52 |
|
53 | |||
53 | void setBoxOutlineVisible(bool visible); |
|
54 | void setBoxOutlineVisible(bool visible); | |
54 | bool boxOutlineVisible(); |
|
55 | bool boxOutlineVisible(); | |
|
56 | void setBoxWidth(qreal width); | |||
|
57 | qreal boxWidth(); | |||
55 | void setBrush(const QBrush &brush); |
|
58 | void setBrush(const QBrush &brush); | |
56 | QBrush brush() const; |
|
59 | QBrush brush() const; | |
57 | void setPen(const QPen &pen); |
|
60 | void setPen(const QPen &pen); | |
@@ -64,6 +67,7 Q_SIGNALS: | |||||
64 | void penChanged(); |
|
67 | void penChanged(); | |
65 | void brushChanged(); |
|
68 | void brushChanged(); | |
66 | void boxOutlineVisibilityChanged(); |
|
69 | void boxOutlineVisibilityChanged(); | |
|
70 | void boxWidthChanged(); | |||
67 |
|
71 | |||
68 | void boxsetsAdded(QList<QBoxSet *> sets); |
|
72 | void boxsetsAdded(QList<QBoxSet *> sets); | |
69 | void boxsetsRemoved(QList<QBoxSet *> sets); |
|
73 | void boxsetsRemoved(QList<QBoxSet *> sets); |
@@ -89,6 +89,7 protected: | |||||
89 | bool m_boxOutlineVisible; |
|
89 | bool m_boxOutlineVisible; | |
90 | int m_index; |
|
90 | int m_index; | |
91 | BoxPlotAnimation *m_animation; |
|
91 | BoxPlotAnimation *m_animation; | |
|
92 | qreal m_boxWidth; | |||
92 |
|
93 | |||
93 | private: |
|
94 | private: | |
94 | Q_DECLARE_PUBLIC(QBoxPlotSeries) |
|
95 | Q_DECLARE_PUBLIC(QBoxPlotSeries) |
@@ -111,6 +111,16 MainWidget::MainWidget(QWidget *parent) : | |||||
111 | connect(m_penTool, SIGNAL(changed()), this, SLOT(changePen())); |
|
111 | connect(m_penTool, SIGNAL(changed()), this, SLOT(changePen())); | |
112 | grid->addWidget(setWhiskersButton, m_rowPos++, 1); |
|
112 | grid->addWidget(setWhiskersButton, m_rowPos++, 1); | |
113 |
|
113 | |||
|
114 | // Box width setting | |||
|
115 | m_boxWidthSB = new QDoubleSpinBox(); | |||
|
116 | m_boxWidthSB->setMinimum(-1.0); | |||
|
117 | m_boxWidthSB->setMaximum(2.0); | |||
|
118 | m_boxWidthSB->setSingleStep(0.1); | |||
|
119 | m_boxWidthSB->setValue(0.5); | |||
|
120 | grid->addWidget(new QLabel("Box width:"), m_rowPos, 0); | |||
|
121 | grid->addWidget(m_boxWidthSB, m_rowPos++, 1); | |||
|
122 | connect(m_boxWidthSB, SIGNAL(valueChanged(double)), this, SLOT(setBoxWidth(double))); | |||
|
123 | ||||
114 | initThemeCombo(grid); |
|
124 | initThemeCombo(grid); | |
115 | initCheckboxes(grid); |
|
125 | initCheckboxes(grid); | |
116 |
|
126 | |||
@@ -249,6 +259,7 void MainWidget::addSeries() | |||||
249 | connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool))); |
|
259 | connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool))); | |
250 |
|
260 | |||
251 | m_series[m_seriesCount]->setBoxOutlineVisible(m_boxOutlined->checkState()); |
|
261 | m_series[m_seriesCount]->setBoxOutlineVisible(m_boxOutlined->checkState()); | |
|
262 | m_series[m_seriesCount]->setBoxWidth(m_boxWidthSB->value()); | |||
252 |
|
263 | |||
253 | m_chart->addSeries(m_series[m_seriesCount]); |
|
264 | m_chart->addSeries(m_series[m_seriesCount]); | |
254 |
|
265 | |||
@@ -459,3 +470,11 void MainWidget::changePen() | |||||
459 | for (int i = 0; i < m_seriesCount; i++) |
|
470 | for (int i = 0; i < m_seriesCount; i++) | |
460 | m_series[i]->setPen(m_penTool->pen()); |
|
471 | m_series[i]->setPen(m_penTool->pen()); | |
461 | } |
|
472 | } | |
|
473 | ||||
|
474 | void MainWidget::setBoxWidth(double width) | |||
|
475 | { | |||
|
476 | qDebug() << "setBoxWidth to " << width; | |||
|
477 | ||||
|
478 | for (int i = 0; i < m_seriesCount; i++) | |||
|
479 | m_series[i]->setBoxWidth(qreal(width)); | |||
|
480 | } |
@@ -31,6 +31,7 | |||||
31 | #include <QBarCategoryAxis> |
|
31 | #include <QBarCategoryAxis> | |
32 | #include <QBoxSet> |
|
32 | #include <QBoxSet> | |
33 | #include <QCheckBox> |
|
33 | #include <QCheckBox> | |
|
34 | #include <QDoubleSpinBox> | |||
34 |
|
35 | |||
35 | class QGridLayout; |
|
36 | class QGridLayout; | |
36 |
|
37 | |||
@@ -70,6 +71,7 private slots: | |||||
70 | void changePen(); |
|
71 | void changePen(); | |
71 | void antialiasingToggled(bool); |
|
72 | void antialiasingToggled(bool); | |
72 | void boxOutlineToggled(bool); |
|
73 | void boxOutlineToggled(bool); | |
|
74 | void setBoxWidth(double width); | |||
73 |
|
75 | |||
74 | private: |
|
76 | private: | |
75 | QChart *m_chart; |
|
77 | QChart *m_chart; | |
@@ -82,6 +84,7 private: | |||||
82 | int m_seriesCount; |
|
84 | int m_seriesCount; | |
83 | QBoxPlotSeries *m_series[10]; |
|
85 | QBoxPlotSeries *m_series[10]; | |
84 | QCheckBox *m_boxOutlined; |
|
86 | QCheckBox *m_boxOutlined; | |
|
87 | QDoubleSpinBox *m_boxWidthSB; | |||
85 | }; |
|
88 | }; | |
86 |
|
89 | |||
87 | #endif // MAINWIDGET_H |
|
90 | #endif // MAINWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now