##// END OF EJS Templates
Doc: Make documentation versioning follow .qmake.conf...
Doc: Make documentation versioning follow .qmake.conf No reason to have hard-coded version numbers in .qdocconf, as they are available from env. variables. Change-Id: I4a118fe0127a20f01af157fbc496e3cb0ba69976 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>

File last commit:

r2845:ae12522d475c
r2882:5b51eec25ba7
Show More
areachartitem.cpp
318 lines | 11.9 KiB | text/x-c | CppLexer
Titta Heikkala
Updated license headers...
r2845 /******************************************************************************
Jani Honkonen
Add license headers
r794 **
Titta Heikkala
Updated license headers...
r2845 ** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
Jani Honkonen
Add license headers
r794 **
Titta Heikkala
Updated license headers...
r2740 ** This file is part of the Qt Charts module.
Jani Honkonen
Add license headers
r794 **
Titta Heikkala
Updated license headers...
r2845 ** $QT_BEGIN_LICENSE:COMM$
Jani Honkonen
Add license headers
r794 **
Titta Heikkala
Updated license headers...
r2845 ** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
Jani Honkonen
Add license headers
r794 **
Titta Heikkala
Updated license headers...
r2845 ** $QT_END_LICENSE$
**
******************************************************************************/
Jani Honkonen
Add license headers
r794
Titta Heikkala
Fix include syntax...
r2714 #include <private/areachartitem_p.h>
#include <QtCharts/QAreaSeries>
#include <private/qareaseries_p.h>
#include <QtCharts/QLineSeries>
#include <private/chartpresenter_p.h>
#include <private/abstractdomain_p.h>
#include <QtGui/QPainter>
#include <QtWidgets/QGraphicsSceneMouseEvent>
#include <QtCore/QDebug>
Michal Klocek
Adds area chart...
r421
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_BEGIN_NAMESPACE
Michal Klocek
Adds area chart...
r421
Michal Klocek
Refactors internals...
r2273 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item)
Miikka Heikkinen
Remove cryptic/obsolete TODOs
r2439 : ChartItem(areaSeries->d_func(),item),
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_series(areaSeries),
m_upper(0),
m_lower(0),
Titta Heikkala
Added possibility to show series value...
r2689 m_pointsVisible(false),
m_pointLabelsVisible(false),
Titta Heikkala
Fix order of initialization...
r2695 m_pointLabelsFormat(areaSeries->pointLabelsFormat()),
Titta Heikkala
Added possibility to show series value...
r2689 m_pointLabelsFont(areaSeries->pointLabelsFont()),
Titta Heikkala
Add pressed, released and doubleClicked signals...
r2739 m_pointLabelsColor(areaSeries->pointLabelsColor()),
Titta Heikkala
Added option to set labels clipping...
r2815 m_pointLabelsClipping(true),
Titta Heikkala
Add pressed, released and doubleClicked signals...
r2739 m_mousePressed(false)
Michal Klocek
Adds area chart...
r421 {
Marek Rosa
Added hovered support to areachart. Might need to be re-thought
r2264 setAcceptHoverEvents(true);
Titta Heikkala
Add pressed, released and doubleClicked signals...
r2739 setFlag(QGraphicsItem::ItemIsSelectable, true);
Michal Klocek
Fixes missing chart area z value intialization
r564 setZValue(ChartPresenter::LineChartZValue);
Titta Heikkala
Fix empty QAreaSeries crash...
r2601 if (m_series->upperSeries())
m_upper = new AreaBoundItem(this, m_series->upperSeries());
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (m_series->lowerSeries())
Michal Klocek
Refactors internals...
r2273 m_lower = new AreaBoundItem(this, m_series->lowerSeries());
Michal Klocek
Adds area chart...
r421
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
Tero Ahola
Visible property to abstract series
r1342 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
Tero Ahola
Added opacity property to QAbstractSeries
r2067 QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 QObject::connect(this, SIGNAL(clicked(QPointF)), areaSeries, SIGNAL(clicked(QPointF)));
Marek Rosa
Added hovered support to areachart. Might need to be re-thought
r2264 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), areaSeries, SIGNAL(hovered(QPointF,bool)));
Titta Heikkala
Add pressed, released and doubleClicked signals...
r2739 QObject::connect(this, SIGNAL(pressed(QPointF)), areaSeries, SIGNAL(pressed(QPointF)));
QObject::connect(this, SIGNAL(released(QPointF)), areaSeries, SIGNAL(released(QPointF)));
QObject::connect(this, SIGNAL(doubleClicked(QPointF)),
areaSeries, SIGNAL(doubleClicked(QPointF)));
Titta Heikkala
Added possibility to show series value...
r2689 QObject::connect(areaSeries, SIGNAL(pointLabelsFormatChanged(QString)),
this, SLOT(handleUpdated()));
QObject::connect(areaSeries, SIGNAL(pointLabelsVisibilityChanged(bool)),
this, SLOT(handleUpdated()));
QObject::connect(areaSeries, SIGNAL(pointLabelsFontChanged(QFont)),
this, SLOT(handleUpdated()));
QObject::connect(areaSeries, SIGNAL(pointLabelsColorChanged(QColor)),
this, SLOT(handleUpdated()));
Titta Heikkala
Added option to set labels clipping...
r2815 QObject::connect(areaSeries, SIGNAL(pointLabelsClippingChanged(bool)),
this, SLOT(handleUpdated()));
Michal Klocek
Adds area chart...
r421
handleUpdated();
}
AreaChartItem::~AreaChartItem()
{
delete m_upper;
delete m_lower;
Tero Ahola
Internal review: fixed minor issues in Area and XySeries
r761 }
Michal Klocek
Adds area chart...
r421
Michal Klocek
Refactors internals...
r2273 void AreaChartItem::setPresenter(ChartPresenter *presenter)
{
Titta Heikkala
Fix empty QAreaSeries crash...
r2601 if (m_upper)
m_upper->setPresenter(presenter);
Michal Klocek
Refactors internals...
r2273 if (m_lower) {
m_lower->setPresenter(presenter);
}
ChartItem::setPresenter(presenter);
}
Michal Klocek
Adds area chart...
r421 QRectF AreaChartItem::boundingRect() const
{
return m_rect;
}
QPainterPath AreaChartItem::shape() const
{
return m_path;
}
void AreaChartItem::updatePath()
{
QPainterPath path;
Michal Klocek
Refactors internals...
r2273 QRectF rect(QPointF(0,0),domain()->size());
Michal Klocek
Adds area chart...
r421
Tero Ahola
Fixed area series paint bug caused by mouse event fix on line series
r1792 path = m_upper->path();
Michal Klocek
Bugfix : black line drawn during areachart paint
r690
sauimone
minor code review issues. indent, spaces, brackets etc.
r743 if (m_lower) {
Miikka Heikkinen
Add Polar chart support...
r2483 // 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.
Tero Ahola
Fixed area series paint bug caused by mouse event fix on line series
r1792 path.connectPath(m_lower->path().toReversed());
sauimone
minor code review issues. indent, spaces, brackets etc.
r743 } else {
Michal Klocek
Adds area chart...
r421 QPointF first = path.pointAtPercent(0);
QPointF last = path.pointAtPercent(1);
Miikka Heikkinen
Add Polar chart support...
r2483 if (presenter()->chartType() == QChart::ChartTypeCartesian) {
path.lineTo(last.x(), rect.bottom());
path.lineTo(first.x(), rect.bottom());
} else { // polar
path.lineTo(rect.center());
}
Michal Klocek
Adds area chart...
r421 }
path.closeSubpath();
Titta Heikkala
Fix zooming in crash...
r2603
// 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.
if (path.boundingRect().height() <= INT_MAX
&& path.boundingRect().width() <= INT_MAX) {
prepareGeometryChange();
m_path = path;
m_rect = path.boundingRect();
update();
}
Michal Klocek
Adds area chart...
r421 }
void AreaChartItem::handleUpdated()
{
Tero Ahola
Fixed isVisible implementation in XY series
r1346 setVisible(m_series->isVisible());
Michal Klocek
Adds visiblePoints handling to area chart
r563 m_pointsVisible = m_series->pointsVisible();
m_linePen = m_series->pen();
Michal Klocek
Unify naming setGeometry -> setLayout
r557 m_brush = m_series->brush();
Michal Klocek
Adds visiblePoints handling to area chart
r563 m_pointPen = m_series->pen();
Tero Ahola
Internal review: fixed minor issues in Area and XySeries
r761 m_pointPen.setWidthF(2 * m_pointPen.width());
Tero Ahola
Added opacity property to QAbstractSeries
r2067 setOpacity(m_series->opacity());
Titta Heikkala
Added possibility to show series value...
r2689 m_pointLabelsFormat = m_series->pointLabelsFormat();
m_pointLabelsVisible = m_series->pointLabelsVisible();
m_pointLabelsFont = m_series->pointLabelsFont();
m_pointLabelsColor = m_series->pointLabelsColor();
Titta Heikkala
Added option to set labels clipping...
r2815 m_pointLabelsClipping = m_series->pointLabelsClipping();
Michal Klocek
Adds area chart...
r421 update();
}
Michal Klocek
Refactors Domain and Axis...
r1698 void AreaChartItem::handleDomainUpdated()
Michal Klocek
Adds area chart...
r421 {
Titta Heikkala
Fix empty QAreaSeries crash...
r2601 if (m_upper) {
AbstractDomain* d = m_upper->domain();
d->setSize(domain()->size());
d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY());
m_upper->handleDomainUpdated();
}
Michal Klocek
Refactors internals...
r2273
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (m_lower) {
Michal Klocek
Domain not sharable again
r2285 AbstractDomain* d = m_lower->domain();
Titta Heikkala
Qt Charts project file structure change...
r2712 d->setSize(domain()->size());
d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY());
m_lower->handleDomainUpdated();
Michal Klocek
Refactors Domain and Axis...
r1698 }
Michal Klocek
Adds area chart...
r421 }
void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Tero Ahola
Squashed bunch of warnings
r611 Q_UNUSED(widget)
Q_UNUSED(option)
Tero Ahola
Fixed isVisible implementation in XY series
r1346 painter->save();
painter->setPen(m_linePen);
painter->setBrush(m_brush);
Miikka Heikkinen
Add Polar chart support...
r2483 QRectF clipRect = QRectF(QPointF(0, 0), domain()->size());
if (presenter()->chartType() == QChart::ChartTypePolar)
painter->setClipRegion(QRegion(clipRect.toRect(), QRegion::Ellipse));
else
painter->setClipRect(clipRect);
Titta Heikkala
Add possibility to set reverse values to axes...
r2781
reversePainter(painter, clipRect);
Tero Ahola
Fixed isVisible implementation in XY series
r1346 painter->drawPath(m_path);
if (m_pointsVisible) {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 painter->setPen(m_pointPen);
painter->drawPoints(m_upper->geometryPoints());
if (m_lower)
painter->drawPoints(m_lower->geometryPoints());
Michal Klocek
Adds visiblePoints handling to area chart
r563 }
Titta Heikkala
Added possibility to show series value...
r2689
Titta Heikkala
Add possibility to set reverse values to axes...
r2781 reversePainter(painter, clipRect);
Titta Heikkala
Added possibility to show series value...
r2689 // Draw series point label
if (m_pointLabelsVisible) {
static const QString xPointTag(QLatin1String("@xPoint"));
static const QString yPointTag(QLatin1String("@yPoint"));
const int labelOffset = 2;
Titta Heikkala
Added option to set labels clipping...
r2815 if (m_pointLabelsClipping)
painter->setClipping(true);
else
painter->setClipping(false);
Titta Heikkala
Added possibility to show series value...
r2689 painter->setFont(m_pointLabelsFont);
painter->setPen(QPen(m_pointLabelsColor));
QFontMetrics fm(painter->font());
Titta Heikkala
Fix area series point labels...
r2778 QString pointLabel;
Titta Heikkala
Added possibility to show series value...
r2689
if (m_series->upperSeries()) {
for (int i(0); i < m_series->upperSeries()->count(); i++) {
Titta Heikkala
Fix area series point labels...
r2778 pointLabel = m_pointLabelsFormat;
Miikka Heikkinen
Added QChart::localizeNumbers...
r2707 pointLabel.replace(xPointTag,
presenter()->numberToString(m_series->upperSeries()->at(i).x()));
pointLabel.replace(yPointTag,
presenter()->numberToString(m_series->upperSeries()->at(i).y()));
Titta Heikkala
Added possibility to show series value...
r2689
// Position text in relation to the point
int pointLabelWidth = fm.width(pointLabel);
QPointF position(m_upper->geometryPoints().at(i));
Titta Heikkala
Add possibility to set reverse values to axes...
r2781 if (!seriesPrivate()->reverseXAxis())
position.setX(position.x() - pointLabelWidth / 2);
else
position.setX(domain()->size().width() - position.x() - pointLabelWidth / 2);
if (!seriesPrivate()->reverseYAxis()) {
position.setY(position.y() - m_series->upperSeries()->pen().width() / 2
- labelOffset);
} else {
position.setY(domain()->size().height() - position.y()
- m_series->upperSeries()->pen().width() / 2 - labelOffset);
}
Titta Heikkala
Added possibility to show series value...
r2689 painter->drawText(position, pointLabel);
}
}
if (m_series->lowerSeries()) {
for (int i(0); i < m_series->lowerSeries()->count(); i++) {
Titta Heikkala
Fix area series point labels...
r2778 pointLabel = m_pointLabelsFormat;
Miikka Heikkinen
Added QChart::localizeNumbers...
r2707 pointLabel.replace(xPointTag,
presenter()->numberToString(m_series->lowerSeries()->at(i).x()));
pointLabel.replace(yPointTag,
presenter()->numberToString(m_series->lowerSeries()->at(i).y()));
Titta Heikkala
Added possibility to show series value...
r2689
// Position text in relation to the point
int pointLabelWidth = fm.width(pointLabel);
QPointF position(m_lower->geometryPoints().at(i));
Titta Heikkala
Add possibility to set reverse values to axes...
r2781 if (!seriesPrivate()->reverseXAxis())
position.setX(position.x() - pointLabelWidth / 2);
else
position.setX(domain()->size().width() - position.x() - pointLabelWidth / 2);
if (!seriesPrivate()->reverseYAxis()) {
position.setY(position.y() - m_series->lowerSeries()->pen().width() / 2
- labelOffset);
} else {
position.setY(domain()->size().height() - position.y()
- m_series->lowerSeries()->pen().width() / 2 - labelOffset);
}
Titta Heikkala
Added possibility to show series value...
r2689 painter->drawText(position, pointLabel);
}
}
}
Tero Ahola
Fixed isVisible implementation in XY series
r1346 painter->restore();
Michal Klocek
Adds area chart...
r421 }
sauimone
minor code review issues. indent, spaces, brackets etc.
r743 void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
Michal Klocek
Refactors click signal to line,area,spline,scatter charts
r571 {
Titta Heikkala
Add pressed, released and doubleClicked signals...
r2739 emit pressed(m_upper->domain()->calculateDomainPoint(event->pos()));
m_lastMousePos = event->pos();
m_mousePressed = true;
Michal Klocek
Fixes mouse handling in base class of chartseries
r1747 ChartItem::mousePressEvent(event);
Michal Klocek
Refactors click signal to line,area,spline,scatter charts
r571 }
Marek Rosa
Added hovered support to areachart. Might need to be re-thought
r2264 void AreaChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Michal Klocek
Refactors internals...
r2273 emit hovered(domain()->calculateDomainPoint(event->pos()), true);
Marek Rosa
Added hovered support to areachart. Might need to be re-thought
r2264 event->accept();
// QGraphicsItem::hoverEnterEvent(event);
}
void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Michal Klocek
Refactors internals...
r2273 emit hovered(domain()->calculateDomainPoint(event->pos()), false);
Marek Rosa
Added hovered support to areachart. Might need to be re-thought
r2264 event->accept();
// QGraphicsItem::hoverEnterEvent(event);
}
Titta Heikkala
Add pressed, released and doubleClicked signals...
r2739 void AreaChartItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Titta Heikkala
Fix clicked, released and doubleClicked signal points...
r2746 emit released(m_upper->domain()->calculateDomainPoint(m_lastMousePos));
if (m_mousePressed)
emit clicked(m_upper->domain()->calculateDomainPoint(m_lastMousePos));
Titta Heikkala
Add pressed, released and doubleClicked signals...
r2739 m_mousePressed = false;
ChartItem::mouseReleaseEvent(event);
}
void AreaChartItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
Titta Heikkala
Fix clicked, released and doubleClicked signal points...
r2746 emit doubleClicked(m_upper->domain()->calculateDomainPoint(m_lastMousePos));
Titta Heikkala
Add pressed, released and doubleClicked signals...
r2739 ChartItem::mouseDoubleClickEvent(event);
}
Michal Klocek
Adds area chart...
r421 #include "moc_areachartitem_p.cpp"
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_END_NAMESPACE