@@ -201,6 +201,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
201 | 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 | 210 | \qmlproperty Pen BoxPlotSeries::pen |
|
205 | 211 | This property configures the pen of the box-and-whiskers items. |
|
206 | 212 | */ |
@@ -213,6 +219,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
213 | 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 | 226 | \qmlsignal BoxPlotSeries::onPenChanged() |
|
217 | 227 | Signal is emitted when the pen for box-and-whiskers items has changed. |
|
218 | 228 | */ |
@@ -85,6 +85,7 void BoxPlotChartItem::handleDataStructureChanged() | |||
|
85 | 85 | box->setBrush(m_series->brush()); |
|
86 | 86 | box->setPen(m_series->pen()); |
|
87 | 87 | box->setBoxOutlined(m_series->boxOutlineVisible()); |
|
88 | box->setBoxWidth(m_series->boxWidth()); | |
|
88 | 89 | } |
|
89 | 90 | updateBoxGeometry(box, s); |
|
90 | 91 | |
@@ -103,6 +104,7 void BoxPlotChartItem::handleUpdatedBars() | |||
|
103 | 104 | item->setBrush(m_series->brush()); |
|
104 | 105 | item->setPen(m_series->pen()); |
|
105 | 106 | item->setBoxOutlined(m_series->boxOutlineVisible()); |
|
107 | item->setBoxWidth(m_series->boxWidth()); | |
|
106 | 108 | } |
|
107 | 109 | // Override with QBoxSet specific settings |
|
108 | 110 | foreach (QBoxSet *set, m_boxTable.keys()) { |
@@ -146,6 +148,8 void BoxPlotChartItem::handleLayoutChanged() | |||
|
146 | 148 | if (m_animation) |
|
147 | 149 | m_animation->setAnimationStart(item); |
|
148 | 150 | |
|
151 | item->setBoxWidth(m_series->boxWidth()); | |
|
152 | ||
|
149 | 153 | bool dirty = updateBoxGeometry(item, item->m_data.m_index); |
|
150 | 154 | if (dirty && m_animation) |
|
151 | 155 | presenter()->startAnimation(m_animation->boxChangeAnimation(item)); |
@@ -77,6 +77,11 void BoxWhiskers::setPen(const QPen &pen) | |||
|
77 | 77 | update(); |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | void BoxWhiskers::setBoxWidth(const qreal width) | |
|
81 | { | |
|
82 | m_boxWidth = width; | |
|
83 | } | |
|
84 | ||
|
80 | 85 | void BoxWhiskers::setLayout(const BoxWhiskersData &data) |
|
81 | 86 | { |
|
82 | 87 | m_data = data; |
@@ -132,8 +137,8 void BoxWhiskers::updateGeometry(AbstractDomain *domain) | |||
|
132 | 137 | m_boundingRect = m_boxPath.boundingRect(); |
|
133 | 138 | |
|
134 | 139 | qreal columnWidth = 1.0 / m_data.m_seriesCount; |
|
135 |
qreal left = |
|
|
136 |
qreal barWidth = columnWidth |
|
|
140 | qreal left = ((1.0 - m_boxWidth) / 2.0) * columnWidth + columnWidth * m_data.m_seriesIndex + m_data.m_index - 0.5; | |
|
141 | qreal barWidth = m_boxWidth * columnWidth; | |
|
137 | 142 | |
|
138 | 143 | QPointF geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_upperExtreme), m_validData); |
|
139 | 144 | if (!m_validData) |
@@ -178,7 +183,7 void BoxWhiskers::updateGeometry(AbstractDomain *domain) | |||
|
178 | 183 | m_boxPath = path; |
|
179 | 184 | m_boundingRect = m_boxPath.boundingRect(); |
|
180 | 185 | |
|
181 |
qreal extra = |
|
|
186 | qreal extra = m_pen.widthF(); | |
|
182 | 187 | m_boundingRect.adjust(-extra, -extra, extra, extra); |
|
183 | 188 | } |
|
184 | 189 |
@@ -55,6 +55,7 public: | |||
|
55 | 55 | void setPen(const QPen &pen); |
|
56 | 56 | void setLayout(const BoxWhiskersData &data); |
|
57 | 57 | void setBoxOutlined(const bool outlined) { m_boxOutlined = outlined; } |
|
58 | void setBoxWidth(const qreal width); | |
|
58 | 59 | |
|
59 | 60 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
60 | 61 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
@@ -87,6 +88,7 private: | |||
|
87 | 88 | QPen m_medianPen; |
|
88 | 89 | QPen m_outlinePen; |
|
89 | 90 | bool m_boxOutlined; |
|
91 | qreal m_boxWidth; | |
|
90 | 92 | BoxWhiskersData m_data; |
|
91 | 93 | QSizeF m_domainSize; |
|
92 | 94 | QRectF m_middleBox; |
@@ -73,6 +73,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
73 | 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 | 82 | \property QBoxPlotSeries::pen |
|
77 | 83 | \brief This property configures the pen of the box-and-whiskers items. |
|
78 | 84 | */ |
@@ -85,6 +91,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
85 | 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 | 98 | \fn void QBoxPlotSeries::penChanged() |
|
89 | 99 | This signal is emitted when the pen of the box-and-whiskers has changed. |
|
90 | 100 | \sa brush |
@@ -94,8 +104,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
94 | 104 | This signal is emitted when the brush of the box-and-whiskers has changed. |
|
95 | 105 | \sa brush |
|
96 | 106 | */ |
|
97 | ||
|
98 | ||
|
99 | 107 | /*! |
|
100 | 108 | \fn virtual SeriesType QBoxPlotSeries::type() const |
|
101 | 109 | \brief Returns type of series. |
@@ -276,6 +284,28 bool QBoxPlotSeries::boxOutlineVisible() | |||
|
276 | 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 | 309 | void QBoxPlotSeries::setBrush(const QBrush &brush) |
|
280 | 310 | { |
|
281 | 311 | Q_D(QBoxPlotSeries); |
@@ -318,7 +348,8 QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q) | |||
|
318 | 348 | : QAbstractSeriesPrivate(q), |
|
319 | 349 | m_pen(QChartPrivate::defaultPen()), |
|
320 | 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 | 34 | Q_OBJECT |
|
35 | 35 | Q_PROPERTY(bool boxOutlineVisible READ boxOutlineVisible WRITE setBoxOutlineVisible NOTIFY boxOutlineVisibilityChanged) |
|
36 | Q_PROPERTY(qreal boxWidth READ boxWidth WRITE setBoxWidth NOTIFY boxWidthChanged) | |
|
36 | 37 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) |
|
37 | 38 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) |
|
38 | 39 | public: |
@@ -52,6 +53,8 public: | |||
|
52 | 53 | |
|
53 | 54 | void setBoxOutlineVisible(bool visible); |
|
54 | 55 | bool boxOutlineVisible(); |
|
56 | void setBoxWidth(qreal width); | |
|
57 | qreal boxWidth(); | |
|
55 | 58 | void setBrush(const QBrush &brush); |
|
56 | 59 | QBrush brush() const; |
|
57 | 60 | void setPen(const QPen &pen); |
@@ -64,6 +67,7 Q_SIGNALS: | |||
|
64 | 67 | void penChanged(); |
|
65 | 68 | void brushChanged(); |
|
66 | 69 | void boxOutlineVisibilityChanged(); |
|
70 | void boxWidthChanged(); | |
|
67 | 71 | |
|
68 | 72 | void boxsetsAdded(QList<QBoxSet *> sets); |
|
69 | 73 | void boxsetsRemoved(QList<QBoxSet *> sets); |
@@ -89,6 +89,7 protected: | |||
|
89 | 89 | bool m_boxOutlineVisible; |
|
90 | 90 | int m_index; |
|
91 | 91 | BoxPlotAnimation *m_animation; |
|
92 | qreal m_boxWidth; | |
|
92 | 93 | |
|
93 | 94 | private: |
|
94 | 95 | Q_DECLARE_PUBLIC(QBoxPlotSeries) |
@@ -111,6 +111,16 MainWidget::MainWidget(QWidget *parent) : | |||
|
111 | 111 | connect(m_penTool, SIGNAL(changed()), this, SLOT(changePen())); |
|
112 | 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 | 124 | initThemeCombo(grid); |
|
115 | 125 | initCheckboxes(grid); |
|
116 | 126 | |
@@ -249,6 +259,7 void MainWidget::addSeries() | |||
|
249 | 259 | connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool))); |
|
250 | 260 | |
|
251 | 261 | m_series[m_seriesCount]->setBoxOutlineVisible(m_boxOutlined->checkState()); |
|
262 | m_series[m_seriesCount]->setBoxWidth(m_boxWidthSB->value()); | |
|
252 | 263 | |
|
253 | 264 | m_chart->addSeries(m_series[m_seriesCount]); |
|
254 | 265 | |
@@ -459,3 +470,11 void MainWidget::changePen() | |||
|
459 | 470 | for (int i = 0; i < m_seriesCount; i++) |
|
460 | 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 | 31 | #include <QBarCategoryAxis> |
|
32 | 32 | #include <QBoxSet> |
|
33 | 33 | #include <QCheckBox> |
|
34 | #include <QDoubleSpinBox> | |
|
34 | 35 | |
|
35 | 36 | class QGridLayout; |
|
36 | 37 | |
@@ -70,6 +71,7 private slots: | |||
|
70 | 71 | void changePen(); |
|
71 | 72 | void antialiasingToggled(bool); |
|
72 | 73 | void boxOutlineToggled(bool); |
|
74 | void setBoxWidth(double width); | |
|
73 | 75 | |
|
74 | 76 | private: |
|
75 | 77 | QChart *m_chart; |
@@ -82,6 +84,7 private: | |||
|
82 | 84 | int m_seriesCount; |
|
83 | 85 | QBoxPlotSeries *m_series[10]; |
|
84 | 86 | QCheckBox *m_boxOutlined; |
|
87 | QDoubleSpinBox *m_boxWidthSB; | |
|
85 | 88 | }; |
|
86 | 89 | |
|
87 | 90 | #endif // MAINWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now