summaryrefslogtreecommitdiffstats
path: root/src/charts/areachart/areachartitem.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-08-30 06:56:05 +0200
committerLiang Qi <liang.qi@qt.io>2016-08-30 06:56:12 +0200
commitbf26aa9d15e525fdcf6fd3f59268418533f06790 (patch)
treee1a12cc49f338bd1ac419a4d774d6f4570df3e40 /src/charts/areachart/areachartitem.cpp
parentd352d707f95c3c4e213585361a3ec737389e301e (diff)
parent8ed3130583510feba58e6f289d1c7b5d051a6663 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Diffstat (limited to 'src/charts/areachart/areachartitem.cpp')
-rw-r--r--src/charts/areachart/areachartitem.cpp94
1 files changed, 64 insertions, 30 deletions
diff --git a/src/charts/areachart/areachartitem.cpp b/src/charts/areachart/areachartitem.cpp
index a51e46ff..df3cc8af 100644
--- a/src/charts/areachart/areachartitem.cpp
+++ b/src/charts/areachart/areachartitem.cpp
@@ -95,10 +95,39 @@ void AreaChartItem::setPresenter(ChartPresenter *presenter)
{
if (m_upper)
m_upper->setPresenter(presenter);
- if (m_lower) {
+ if (m_lower)
m_lower->setPresenter(presenter);
+ ChartItem::setPresenter(presenter);
+}
+
+void AreaChartItem::setUpperSeries(QLineSeries *series)
+{
+ delete m_upper;
+ if (series)
+ m_upper = new AreaBoundItem(this, series);
+ else
+ m_upper = 0;
+ if (m_upper) {
+ m_upper->setPresenter(presenter());
+ fixEdgeSeriesDomain(m_upper);
+ } else {
+ updatePath();
+ }
+}
+
+void AreaChartItem::setLowerSeries(QLineSeries *series)
+{
+ delete m_lower;
+ if (series)
+ m_lower = new AreaBoundItem(this, series);
+ else
+ m_lower = 0;
+ if (m_lower) {
+ m_lower->setPresenter(presenter());
+ fixEdgeSeriesDomain(m_lower);
+ } else {
+ updatePath();
}
- ChartItem::setPresenter(presenter);
}
QRectF AreaChartItem::boundingRect() const
@@ -116,31 +145,34 @@ void AreaChartItem::updatePath()
QPainterPath path;
QRectF rect(QPointF(0,0),domain()->size());
- path = m_upper->path();
-
- if (m_lower) {
- // Note: Polarcharts always draw area correctly only when both series have equal width or are
- // fully displayed. If one series is partally off-chart, the connecting line between
- // the series does not attach to the end of the partially hidden series but to the point
- // where it intersects the axis line. The problem is especially noticeable when one of the series
- // is entirely off-chart, in which case the connecting line connects two ends of the
- // visible series.
- // This happens because we get the paths from linechart, which omits off-chart segments.
- // To properly fix, linechart would need to provide true full path, in right, left, and the rest
- // portions to enable proper clipping. However, combining those to single visually unified area
- // would be a nightmare, since they would have to be painted separately.
- path.connectPath(m_lower->path().toReversed());
- } else {
- QPointF first = path.pointAtPercent(0);
- QPointF last = path.pointAtPercent(1);
- if (presenter()->chartType() == QChart::ChartTypeCartesian) {
- path.lineTo(last.x(), rect.bottom());
- path.lineTo(first.x(), rect.bottom());
- } else { // polar
- path.lineTo(rect.center());
+ if (m_upper) {
+ path = m_upper->path();
+
+ if (m_lower) {
+ // Note: Polarcharts draw area correctly only when both series have equal width or are
+ // fully displayed. If one series is partally off-chart, the connecting line between
+ // the series does not attach to the end of the partially hidden series but to the point
+ // where it intersects the axis line. The problem is especially noticeable when one of
+ // the series is entirely off-chart, in which case the connecting line connects two
+ // ends of the visible series.
+ // This happens because we get the paths from linechart, which omits off-chart segments.
+ // To properly fix, linechart would need to provide true full path, in right, left,
+ // and the rest portions to enable proper clipping. However, combining those to single
+ // visually unified area would be a nightmare, since they would have to be painted
+ // separately.
+ path.connectPath(m_lower->path().toReversed());
+ } else {
+ QPointF first = path.pointAtPercent(0);
+ QPointF last = path.pointAtPercent(1);
+ if (presenter()->chartType() == QChart::ChartTypeCartesian) {
+ path.lineTo(last.x(), rect.bottom());
+ path.lineTo(first.x(), rect.bottom());
+ } else { // polar
+ path.lineTo(rect.center());
+ }
}
+ path.closeSubpath();
}
- path.closeSubpath();
// Only zoom in if the bounding rect of the path fits inside int limits. QWidget::update() uses
// a region that has to be compatible with QRect.
@@ -199,6 +231,7 @@ void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
{
Q_UNUSED(widget)
Q_UNUSED(option)
+
painter->save();
painter->setPen(m_linePen);
painter->setBrush(m_brush);
@@ -211,7 +244,8 @@ void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
painter->drawPath(m_path);
if (m_pointsVisible) {
painter->setPen(m_pointPen);
- painter->drawPoints(m_upper->geometryPoints());
+ if (m_upper)
+ painter->drawPoints(m_upper->geometryPoints());
if (m_lower)
painter->drawPoints(m_lower->geometryPoints());
}
@@ -275,7 +309,7 @@ void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
- emit pressed(m_upper->domain()->calculateDomainPoint(event->pos()));
+ emit pressed(domain()->calculateDomainPoint(event->pos()));
m_lastMousePos = event->pos();
m_mousePressed = true;
ChartItem::mousePressEvent(event);
@@ -297,16 +331,16 @@ void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void AreaChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- emit released(m_upper->domain()->calculateDomainPoint(m_lastMousePos));
+ emit released(domain()->calculateDomainPoint(m_lastMousePos));
if (m_mousePressed)
- emit clicked(m_upper->domain()->calculateDomainPoint(m_lastMousePos));
+ emit clicked(domain()->calculateDomainPoint(m_lastMousePos));
m_mousePressed = false;
ChartItem::mouseReleaseEvent(event);
}
void AreaChartItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
- emit doubleClicked(m_upper->domain()->calculateDomainPoint(m_lastMousePos));
+ emit doubleClicked(domain()->calculateDomainPoint(m_lastMousePos));
ChartItem::mouseDoubleClickEvent(event);
}