summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Salmela <mika.salmela@digia.com>2013-06-14 18:15:37 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2013-06-17 09:24:02 +0300
commit1dbaa17880af3dfff72c5e6410ee83f05d3c0630 (patch)
tree1de43fbb49205d62fd7420f5b1066d51b269845f
parentcc63ecb91431141be4503ee66d354d57db8f56fe (diff)
Property to control box width
Also fix bounding rect to get rid of some pen width related drawing artifacts. Change-Id: Ib498545cecd497d845031a3ccba572a9cba8e91d Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com> Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
-rw-r--r--plugins/declarative/declarativeboxplotseries.cpp10
-rw-r--r--src/boxplotchart/boxplotchartitem.cpp4
-rw-r--r--src/boxplotchart/boxwhiskers.cpp11
-rw-r--r--src/boxplotchart/boxwhiskers_p.h2
-rw-r--r--src/boxplotchart/qboxplotseries.cpp37
-rw-r--r--src/boxplotchart/qboxplotseries.h4
-rw-r--r--src/boxplotchart/qboxplotseries_p.h1
-rw-r--r--tests/boxplottester/mainwidget.cpp19
-rw-r--r--tests/boxplottester/mainwidget.h3
9 files changed, 85 insertions, 6 deletions
diff --git a/plugins/declarative/declarativeboxplotseries.cpp b/plugins/declarative/declarativeboxplotseries.cpp
index e5119749..33973f87 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 e9f9ea20..eff7388c 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 a50f5713..a06262b4 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 0168c19a..dfea6235 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 ce3c674b..2d05f983 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 ffedbfc0..5517ed79 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<QBoxSet *> sets);
void boxsetsRemoved(QList<QBoxSet *> sets);
diff --git a/src/boxplotchart/qboxplotseries_p.h b/src/boxplotchart/qboxplotseries_p.h
index 4e415dc7..c3a0e08b 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 62a5521f..02bbaafa 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 d2825ded..cc329b0c 100644
--- a/tests/boxplottester/mainwidget.h
+++ b/tests/boxplottester/mainwidget.h
@@ -31,6 +31,7 @@
#include <QBarCategoryAxis>
#include <QBoxSet>
#include <QCheckBox>
+#include <QDoubleSpinBox>
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