summaryrefslogtreecommitdiffstats
path: root/src/charts/splinechart/splinechartitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/charts/splinechart/splinechartitem.cpp')
-rw-r--r--src/charts/splinechart/splinechartitem.cpp86
1 files changed, 74 insertions, 12 deletions
diff --git a/src/charts/splinechart/splinechartitem.cpp b/src/charts/splinechart/splinechartitem.cpp
index 7e0601e4..4dba01f2 100644
--- a/src/charts/splinechart/splinechartitem.cpp
+++ b/src/charts/splinechart/splinechartitem.cpp
@@ -56,6 +56,7 @@ SplineChartItem::SplineChartItem(QSplineSeries *series, QGraphicsItem *item)
connect(m_series->d_func(), &QXYSeriesPrivate::seriesUpdated,
this, &SplineChartItem::handleSeriesUpdated);
connect(series, &QXYSeries::lightMarkerChanged, this, &SplineChartItem::handleSeriesUpdated);
+ connect(series, &QXYSeries::selectedLightMarkerChanged, this, &SplineChartItem::handleSeriesUpdated);
connect(series, &QXYSeries::markerSizeChanged, this, &SplineChartItem::handleSeriesUpdated);
connect(series, &QXYSeries::visibleChanged, this, &SplineChartItem::handleSeriesUpdated);
connect(series, &QXYSeries::opacityChanged, this, &SplineChartItem::handleSeriesUpdated);
@@ -69,8 +70,13 @@ SplineChartItem::SplineChartItem(QSplineSeries *series, QGraphicsItem *item)
this, &SplineChartItem::handleSeriesUpdated);
connect(series, &QXYSeries::pointLabelsClippingChanged,
this, &SplineChartItem::handleSeriesUpdated);
+ connect(series, &QSplineSeries::selectedColorChanged,
+ this, &SplineChartItem::handleSeriesUpdated);
connect(series, &QLineSeries::selectedPointsChanged,
this, &SplineChartItem::handleSeriesUpdated);
+ connect(series, &QSplineSeries::pointsConfigurationChanged,
+ this, &SplineChartItem::handleSeriesUpdated);
+
handleSeriesUpdated();
}
@@ -316,7 +322,8 @@ void SplineChartItem::updateGeometry()
// For mouse interactivity, we have to add the rects *after* the 'createStroke',
// as we don't need the outline - we need it filled up.
- if (!m_series->lightMarker().isNull()) {
+ if (!m_series->lightMarker().isNull() || (!m_series->selectedLightMarker().isNull()
+ && !m_series->selectedPoints().isEmpty())) {
// +1, +2: a margin to guarantee we cover all of the pixmap
qreal markerHalfSize = (m_series->markerSize() / 2.0) + 1;
qreal markerSize = m_series->markerSize() + 2;
@@ -452,6 +459,8 @@ void SplineChartItem::handleSeriesUpdated()
m_markerSize = m_series->markerSize();
m_pointLabelsFont = m_series->pointLabelsFont();
m_pointLabelsColor = m_series->pointLabelsColor();
+ m_selectedPoints = m_series->selectedPoints();
+ m_selectedColor = m_series->selectedColor();
bool labelClippingChanged = m_pointLabelsClipping != m_series->pointLabelsClipping();
m_pointLabelsClipping = m_series->pointLabelsClipping();
// Update whole chart in case label clipping changed as labels can be outside series area
@@ -495,18 +504,12 @@ void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
painter->drawPath(m_path);
- if (m_pointsVisible) {
- painter->setPen(m_pointPen);
- if (m_series->chart()->chartType() == QChart::ChartTypePolar)
- painter->drawPoints(m_visiblePoints);
- else
- painter->drawPoints(geometryPoints());
- }
-
int pointLabelsOffset = m_linePen.width() / 2;
- // Draw markers if a marker has been set (set to QImage() to disable)
- if (!m_series->lightMarker().isNull()) {
+ // Draw markers if a marker or marker for selected points only has been
+ // set (set to QImage() to disable)
+ if (!m_series->lightMarker().isNull() || (!m_series->selectedLightMarker().isNull()
+ && !m_series->selectedPoints().isEmpty())) {
const QImage &marker = m_series->lightMarker();
const QImage &selectedMarker = m_series->selectedLightMarker();
qreal markerHalfSize = m_markerSize / 2.0;
@@ -517,7 +520,7 @@ void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
// light markers are independent features. Therefore m_pointsVisible
// is not used here as light markers are drawn if lightMarker is not null.
// However points visibility configuration can be still used here.
- bool drawPoint = true;
+ bool drawPoint = !m_series->lightMarker().isNull();
if (m_pointsConfiguration.contains(i)) {
const auto &conf = m_pointsConfiguration[i];
@@ -549,6 +552,65 @@ void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
m_series->d_func()->drawSeriesPointLabels(painter, m_points, pointLabelsOffset);
}
+ painter->setPen(m_pointPen);
+ if (m_series->chart()->chartType() == QChart::ChartTypePolar && m_pointsVisible) {
+ painter->drawPoints(m_visiblePoints);
+ } else {
+ const bool simpleDraw = m_selectedPoints.isEmpty() && m_pointsConfiguration.isEmpty();
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(m_linePen.color());
+ painter->setClipping(true);
+
+ if (m_pointsVisible && simpleDraw && m_series->lightMarker().isNull()) {
+ for (int i = 0; i < m_points.size(); ++i)
+ painter->drawEllipse(m_points.at(i), m_markerSize, m_markerSize);
+ } else if (!simpleDraw) {
+ qreal ptSize = m_markerSize;
+ for (int i = 0; i < m_points.size(); ++i) {
+ if (clipRect.contains(m_points.at(i))) {
+ painter->save();
+ ptSize = m_markerSize;
+ bool drawPoint = m_pointsVisible && m_series->lightMarker().isNull();
+ if (m_pointsConfiguration.contains(i)) {
+ const auto &conf = m_pointsConfiguration[i];
+ if (conf.contains(QXYSeries::PointConfiguration::Visibility)) {
+ drawPoint =
+ m_pointsConfiguration[i][QXYSeries::PointConfiguration::Visibility]
+ .toBool();
+ }
+
+ if (drawPoint) {
+ if (conf.contains(QXYSeries::PointConfiguration::Size)) {
+ ptSize = m_pointsConfiguration[i][QXYSeries::PointConfiguration::Size]
+ .toReal();
+ }
+
+ if (conf.contains(QXYSeries::PointConfiguration::Color)) {
+ painter->setBrush(
+ m_pointsConfiguration[i][QXYSeries::PointConfiguration::Color]
+ .value<QColor>());
+ }
+ }
+ }
+
+ if (m_series->isPointSelected(i)) {
+ // Selected points are drawn regardless of m_pointsVisible settings and
+ // custom point configuration. However, they are not drawn if light markers
+ // are used. The reason of this is to avoid displaying selected point
+ // over selected light marker.
+ drawPoint = m_series->selectedLightMarker().isNull();
+ ptSize = ptSize * 1.5;
+ if (m_selectedColor.isValid())
+ painter->setBrush(m_selectedColor);
+ }
+
+ if (drawPoint)
+ painter->drawEllipse(m_points.at(i), ptSize, ptSize);
+ painter->restore();
+ }
+ }
+ }
+ }
painter->restore();
}