diff --git a/plugins/declarative/declarativeboxplotseries.cpp b/plugins/declarative/declarativeboxplotseries.cpp index e511974..33973f8 100644 --- a/plugins/declarative/declarativeboxplotseries.cpp +++ b/plugins/declarative/declarativeboxplotseries.cpp @@ -201,6 +201,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE This property configures the visibility of the middle box outline. */ /*! + \qmlproperty qreal BoxPlotSeries::boxWidth + This property configures the width of the box-and-whiskers item. The value signifies the relative + width of the box-and-whiskers item inside its own slot. The value can between 0.0 and 1.0. Negative values + are clamped to 0.0 and values over 1.0 are clamped to 1.0. +*/ +/*! \qmlproperty Pen BoxPlotSeries::pen This property configures the pen of the box-and-whiskers items. */ @@ -213,6 +219,10 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Signal is emitted when the middle box outline visibility is changed. */ /*! + \qmlsignal BoxPlotSeries::onBoxWidthChanged() + Signal is emitted when the width of the box-and-whiskers item is changed. + */ +/*! \qmlsignal BoxPlotSeries::onPenChanged() Signal is emitted when the pen for box-and-whiskers items has changed. */ diff --git a/src/boxplotchart/boxplotchartitem.cpp b/src/boxplotchart/boxplotchartitem.cpp index e9f9ea2..eff7388 100644 --- a/src/boxplotchart/boxplotchartitem.cpp +++ b/src/boxplotchart/boxplotchartitem.cpp @@ -85,6 +85,7 @@ void BoxPlotChartItem::handleDataStructureChanged() box->setBrush(m_series->brush()); box->setPen(m_series->pen()); box->setBoxOutlined(m_series->boxOutlineVisible()); + box->setBoxWidth(m_series->boxWidth()); } updateBoxGeometry(box, s); @@ -103,6 +104,7 @@ void BoxPlotChartItem::handleUpdatedBars() item->setBrush(m_series->brush()); item->setPen(m_series->pen()); item->setBoxOutlined(m_series->boxOutlineVisible()); + item->setBoxWidth(m_series->boxWidth()); } // Override with QBoxSet specific settings foreach (QBoxSet *set, m_boxTable.keys()) { @@ -146,6 +148,8 @@ void BoxPlotChartItem::handleLayoutChanged() if (m_animation) m_animation->setAnimationStart(item); + item->setBoxWidth(m_series->boxWidth()); + bool dirty = updateBoxGeometry(item, item->m_data.m_index); if (dirty && m_animation) presenter()->startAnimation(m_animation->boxChangeAnimation(item)); diff --git a/src/boxplotchart/boxwhiskers.cpp b/src/boxplotchart/boxwhiskers.cpp index a50f571..a06262b 100644 --- a/src/boxplotchart/boxwhiskers.cpp +++ b/src/boxplotchart/boxwhiskers.cpp @@ -77,6 +77,11 @@ void BoxWhiskers::setPen(const QPen &pen) update(); } +void BoxWhiskers::setBoxWidth(const qreal width) +{ + m_boxWidth = width; +} + void BoxWhiskers::setLayout(const BoxWhiskersData &data) { m_data = data; @@ -132,8 +137,8 @@ void BoxWhiskers::updateGeometry(AbstractDomain *domain) m_boundingRect = m_boxPath.boundingRect(); qreal columnWidth = 1.0 / m_data.m_seriesCount; - qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex + m_data.m_index - 0.5; - qreal barWidth = columnWidth / 2.0; + qreal left = ((1.0 - m_boxWidth) / 2.0) * columnWidth + columnWidth * m_data.m_seriesIndex + m_data.m_index - 0.5; + qreal barWidth = m_boxWidth * columnWidth; QPointF geometryPoint = m_domain->calculateGeometryPoint(QPointF(left, m_data.m_upperExtreme), m_validData); if (!m_validData) @@ -178,7 +183,7 @@ void BoxWhiskers::updateGeometry(AbstractDomain *domain) m_boxPath = path; m_boundingRect = m_boxPath.boundingRect(); - qreal extra = (m_pen.widthF() / 2.0); + qreal extra = m_pen.widthF(); m_boundingRect.adjust(-extra, -extra, extra, extra); } diff --git a/src/boxplotchart/boxwhiskers_p.h b/src/boxplotchart/boxwhiskers_p.h index 0168c19..dfea623 100644 --- a/src/boxplotchart/boxwhiskers_p.h +++ b/src/boxplotchart/boxwhiskers_p.h @@ -55,6 +55,7 @@ public: void setPen(const QPen &pen); void setLayout(const BoxWhiskersData &data); void setBoxOutlined(const bool outlined) { m_boxOutlined = outlined; } + void setBoxWidth(const qreal width); void mousePressEvent(QGraphicsSceneMouseEvent *event); void hoverEnterEvent(QGraphicsSceneHoverEvent *event); @@ -87,6 +88,7 @@ private: QPen m_medianPen; QPen m_outlinePen; bool m_boxOutlined; + qreal m_boxWidth; BoxWhiskersData m_data; QSizeF m_domainSize; QRectF m_middleBox; diff --git a/src/boxplotchart/qboxplotseries.cpp b/src/boxplotchart/qboxplotseries.cpp index ce3c674..2d05f98 100644 --- a/src/boxplotchart/qboxplotseries.cpp +++ b/src/boxplotchart/qboxplotseries.cpp @@ -73,6 +73,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE \brief This property configures the visibility of the middle box outline. */ /*! + \property QBoxPlotSeries::boxWidth + \brief This property configures the width of the box-and-whiskers item. The value signifies the relative + width of the box-and-whiskers item inside its own slot. The value can between 0.0 and 1.0. Negative values + are clamped to 0.0 and values over 1.0 are clamped to 1.0. +*/ +/*! \property QBoxPlotSeries::pen \brief This property configures the pen of the box-and-whiskers items. */ @@ -85,6 +91,10 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Signal is emitted when the middle box outline visibility is changed. */ /*! + \fn void QBoxPlotSeries::boxWidthChanged() + Signal is emitted when the width of the box-and-whiskers item is changed. +*/ +/*! \fn void QBoxPlotSeries::penChanged() This signal is emitted when the pen of the box-and-whiskers has changed. \sa brush @@ -94,8 +104,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE This signal is emitted when the brush of the box-and-whiskers has changed. \sa brush */ - - /*! \fn virtual SeriesType QBoxPlotSeries::type() const \brief Returns type of series. @@ -276,6 +284,28 @@ bool QBoxPlotSeries::boxOutlineVisible() return d->m_boxOutlineVisible; } +void QBoxPlotSeries::setBoxWidth(qreal width) +{ + Q_D(QBoxPlotSeries); + + if (width != d->m_boxWidth) { + if (width < 0.0) + width = 0.0; + if (width > 1.0) + width = 1.0; + d->m_boxWidth = width; + emit d->updatedLayout(); + emit boxWidthChanged(); + } +} + +qreal QBoxPlotSeries::boxWidth() +{ + Q_D(QBoxPlotSeries); + + return d->m_boxWidth; +} + void QBoxPlotSeries::setBrush(const QBrush &brush) { Q_D(QBoxPlotSeries); @@ -318,7 +348,8 @@ QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q) : QAbstractSeriesPrivate(q), m_pen(QChartPrivate::defaultPen()), m_brush(QChartPrivate::defaultBrush()), - m_boxOutlineVisible(true) + m_boxOutlineVisible(true), + m_boxWidth(0.5) { } diff --git a/src/boxplotchart/qboxplotseries.h b/src/boxplotchart/qboxplotseries.h index ffedbfc..5517ed7 100644 --- a/src/boxplotchart/qboxplotseries.h +++ b/src/boxplotchart/qboxplotseries.h @@ -33,6 +33,7 @@ class QTCOMMERCIALCHART_EXPORT QBoxPlotSeries : public QAbstractSeries { Q_OBJECT Q_PROPERTY(bool boxOutlineVisible READ boxOutlineVisible WRITE setBoxOutlineVisible NOTIFY boxOutlineVisibilityChanged) + Q_PROPERTY(qreal boxWidth READ boxWidth WRITE setBoxWidth NOTIFY boxWidthChanged) Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) public: @@ -52,6 +53,8 @@ public: void setBoxOutlineVisible(bool visible); bool boxOutlineVisible(); + void setBoxWidth(qreal width); + qreal boxWidth(); void setBrush(const QBrush &brush); QBrush brush() const; void setPen(const QPen &pen); @@ -64,6 +67,7 @@ Q_SIGNALS: void penChanged(); void brushChanged(); void boxOutlineVisibilityChanged(); + void boxWidthChanged(); void boxsetsAdded(QList sets); void boxsetsRemoved(QList sets); diff --git a/src/boxplotchart/qboxplotseries_p.h b/src/boxplotchart/qboxplotseries_p.h index 4e415dc..c3a0e08 100644 --- a/src/boxplotchart/qboxplotseries_p.h +++ b/src/boxplotchart/qboxplotseries_p.h @@ -89,6 +89,7 @@ protected: bool m_boxOutlineVisible; int m_index; BoxPlotAnimation *m_animation; + qreal m_boxWidth; private: Q_DECLARE_PUBLIC(QBoxPlotSeries) diff --git a/tests/boxplottester/mainwidget.cpp b/tests/boxplottester/mainwidget.cpp index 62a5521..02bbaaf 100644 --- a/tests/boxplottester/mainwidget.cpp +++ b/tests/boxplottester/mainwidget.cpp @@ -111,6 +111,16 @@ MainWidget::MainWidget(QWidget *parent) : connect(m_penTool, SIGNAL(changed()), this, SLOT(changePen())); grid->addWidget(setWhiskersButton, m_rowPos++, 1); + // Box width setting + m_boxWidthSB = new QDoubleSpinBox(); + m_boxWidthSB->setMinimum(-1.0); + m_boxWidthSB->setMaximum(2.0); + m_boxWidthSB->setSingleStep(0.1); + m_boxWidthSB->setValue(0.5); + grid->addWidget(new QLabel("Box width:"), m_rowPos, 0); + grid->addWidget(m_boxWidthSB, m_rowPos++, 1); + connect(m_boxWidthSB, SIGNAL(valueChanged(double)), this, SLOT(setBoxWidth(double))); + initThemeCombo(grid); initCheckboxes(grid); @@ -249,6 +259,7 @@ void MainWidget::addSeries() connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool))); m_series[m_seriesCount]->setBoxOutlineVisible(m_boxOutlined->checkState()); + m_series[m_seriesCount]->setBoxWidth(m_boxWidthSB->value()); m_chart->addSeries(m_series[m_seriesCount]); @@ -459,3 +470,11 @@ void MainWidget::changePen() for (int i = 0; i < m_seriesCount; i++) m_series[i]->setPen(m_penTool->pen()); } + +void MainWidget::setBoxWidth(double width) +{ + qDebug() << "setBoxWidth to " << width; + + for (int i = 0; i < m_seriesCount; i++) + m_series[i]->setBoxWidth(qreal(width)); +} diff --git a/tests/boxplottester/mainwidget.h b/tests/boxplottester/mainwidget.h index d2825de..cc329b0 100644 --- a/tests/boxplottester/mainwidget.h +++ b/tests/boxplottester/mainwidget.h @@ -31,6 +31,7 @@ #include #include #include +#include class QGridLayout; @@ -70,6 +71,7 @@ private slots: void changePen(); void antialiasingToggled(bool); void boxOutlineToggled(bool); + void setBoxWidth(double width); private: QChart *m_chart; @@ -82,6 +84,7 @@ private: int m_seriesCount; QBoxPlotSeries *m_series[10]; QCheckBox *m_boxOutlined; + QDoubleSpinBox *m_boxWidthSB; }; #endif // MAINWIDGET_H