diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-10-12 03:02:09 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-10-12 03:02:09 +0200 |
commit | 88e67e7686fa564e81a770a18879cc281e620222 (patch) | |
tree | e0de67bd85401b36373268e18a5d11efaee8f1b1 | |
parent | 911bc706521021202d4c45a0ed2f7e5edd4e99af (diff) | |
parent | a692d9a826d864e91b668415aea266228c2ae323 (diff) |
Merge remote-tracking branch 'origin/5.13' into 5.14
Change-Id: I0503eb5a77d2759d291f2bb85e7dd7b2c7eb07c2
-rw-r--r-- | src/charts/axis/barcategoryaxis/chartbarcategoryaxisx.cpp | 4 | ||||
-rw-r--r-- | src/charts/axis/barcategoryaxis/chartbarcategoryaxisy.cpp | 4 | ||||
-rw-r--r-- | src/charts/linechart/linechartitem.cpp | 40 | ||||
-rw-r--r-- | src/charts/qchartview.cpp | 11 | ||||
-rw-r--r-- | src/charts/qchartview.h | 13 | ||||
-rw-r--r-- | src/chartsqml2/declarativecategoryaxis.cpp | 8 | ||||
-rw-r--r-- | src/chartsqml2/declarativecategoryaxis_p.h | 2 |
7 files changed, 49 insertions, 33 deletions
diff --git a/src/charts/axis/barcategoryaxis/chartbarcategoryaxisx.cpp b/src/charts/axis/barcategoryaxis/chartbarcategoryaxisx.cpp index a515d797..26a159b4 100644 --- a/src/charts/axis/barcategoryaxis/chartbarcategoryaxisx.cpp +++ b/src/charts/axis/barcategoryaxis/chartbarcategoryaxisx.cpp @@ -59,7 +59,7 @@ QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const return points; qreal adjustedMin = min() + 0.5; - qreal offset = (qCeil(adjustedMin) - adjustedMin) * delta; + qreal offset = (qRound(adjustedMin) - adjustedMin) * delta; int count = qFloor(range); if (count < 1) @@ -80,7 +80,7 @@ QStringList ChartBarCategoryAxisX::createCategoryLabels(const QVector<qreal>& la qreal d = (max() - min()) / gridRect.width(); for (int i = 0; i < layout.count() - 1; ++i) { - qreal x = qFloor((((layout[i] + layout[i + 1]) / 2 - gridRect.left()) * d + min() + 0.5)); + int x = qFloor((((layout[i] + layout[i + 1]) / 2 - gridRect.left()) * d + min() + 0.5)); if (x < max() && (x >= 0) && x < m_categoriesAxis->categories().count()) { result << m_categoriesAxis->categories().at(x); } else { diff --git a/src/charts/axis/barcategoryaxis/chartbarcategoryaxisy.cpp b/src/charts/axis/barcategoryaxis/chartbarcategoryaxisy.cpp index bc5bf97f..a8ef0aa5 100644 --- a/src/charts/axis/barcategoryaxis/chartbarcategoryaxisy.cpp +++ b/src/charts/axis/barcategoryaxis/chartbarcategoryaxisy.cpp @@ -59,7 +59,7 @@ QVector<qreal> ChartBarCategoryAxisY::calculateLayout() const return points; qreal adjustedMin = min() + 0.5; - qreal offset = (qCeil(adjustedMin) - adjustedMin) * delta; + qreal offset = (qRound(adjustedMin) - adjustedMin) * delta; int count = qFloor(range); if (count < 1) @@ -80,7 +80,7 @@ QStringList ChartBarCategoryAxisY::createCategoryLabels(const QVector<qreal>& la qreal d = (max() - min()) / gridRect.height(); for (int i = 0; i < layout.count() - 1; ++i) { - qreal x = qFloor(((gridRect.height() - (layout[i + 1] + layout[i]) / 2 + gridRect.top()) * d + min() + 0.5)); + int x = qFloor(((gridRect.height() - (layout[i + 1] + layout[i]) / 2 + gridRect.top()) * d + min() + 0.5)); if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { result << m_categoriesAxis->categories().at(x); } else { diff --git a/src/charts/linechart/linechartitem.cpp b/src/charts/linechart/linechartitem.cpp index 99e16d29..c6eb2d07 100644 --- a/src/charts/linechart/linechartitem.cpp +++ b/src/charts/linechart/linechartitem.cpp @@ -291,19 +291,8 @@ void LineChartItem::updateGeometry() // because shape doesn't get clipped. It doesn't seem possible to do sensibly. } else { // not polar linePath.moveTo(points.at(0)); - if (m_pointsVisible) { - int size = m_linePen.width(); - linePath.addEllipse(points.at(0), size, size); - linePath.moveTo(points.at(0)); - for (int i = 1; i < points.size(); i++) { - linePath.lineTo(points.at(i)); - linePath.addEllipse(points.at(i), size, size); - linePath.moveTo(points.at(i)); - } - } else { - for (int i = 1; i < points.size(); i++) - linePath.lineTo(points.at(i)); - } + for (int i = 1; i < points.size(); i++) + linePath.lineTo(points.at(i)); fullPath = linePath; } @@ -407,19 +396,12 @@ void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt painter->setClipRect(clipRect); } - if (m_pointsVisible) { - painter->setBrush(m_linePen.color()); + if (m_linePen.style() != Qt::SolidLine || alwaysUsePath) { + // If pen style is not solid line, use path painting to ensure proper pattern continuity painter->drawPath(m_linePath); } else { - painter->setBrush(QBrush(Qt::NoBrush)); - if (m_linePen.style() != Qt::SolidLine || alwaysUsePath) { - // If pen style is not solid line, always fall back to path painting - // to ensure proper continuity of the pattern - painter->drawPath(m_linePath); - } else { - for (int i(1); i < m_linePoints.size(); i++) - painter->drawLine(m_linePoints.at(i - 1), m_linePoints.at(i)); - } + for (int i = 1; i < m_linePoints.size(); ++i) + painter->drawLine(m_linePoints.at(i - 1), m_linePoints.at(i)); } if (m_pointLabelsVisible) { @@ -432,6 +414,16 @@ void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt painter->restore(); + if (m_pointsVisible) { + // draw points that lie inside clipRect only + qreal ptSize = m_linePen.width() * 1.5; + painter->setPen(Qt::NoPen); + painter->setBrush(m_linePen.color()); + for (int i = 0; i < m_linePoints.size(); ++i) { + if (clipRect.contains(m_linePoints.at(i))) + painter->drawEllipse(m_linePoints.at(i), ptSize, ptSize); + } + } } void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) diff --git a/src/charts/qchartview.cpp b/src/charts/qchartview.cpp index b8936f03..0da6e18a 100644 --- a/src/charts/qchartview.cpp +++ b/src/charts/qchartview.cpp @@ -261,6 +261,17 @@ void QChartView::mouseReleaseEvent(QMouseEvent *event) #endif } +#ifdef Q_OS_MACOS +#if QT_CONFIG(wheelevent) +void QChartView::wheelEvent(QWheelEvent *event) +{ + Q_UNUSED(event) + // We just need to override wheelEvent, or scrolling won't work correctly on macOS trackpad + // (QTBUG-77403) +} +#endif +#endif + /*! Resizes and updates the chart area using the data specified by \a event. */ diff --git a/src/charts/qchartview.h b/src/charts/qchartview.h index f8056487..f41fe56e 100644 --- a/src/charts/qchartview.h +++ b/src/charts/qchartview.h @@ -70,10 +70,15 @@ public: void setChart(QChart *chart); protected: - void resizeEvent(QResizeEvent *event); - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); + void resizeEvent(QResizeEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; +#ifdef Q_OS_MACOS +#if QT_CONFIG(wheelevent) + void wheelEvent(QWheelEvent *event) override; +#endif +#endif QScopedPointer<QChartViewPrivate> d_ptr; diff --git a/src/chartsqml2/declarativecategoryaxis.cpp b/src/chartsqml2/declarativecategoryaxis.cpp index 1b1826fd..8f6a2b20 100644 --- a/src/chartsqml2/declarativecategoryaxis.cpp +++ b/src/chartsqml2/declarativecategoryaxis.cpp @@ -64,6 +64,14 @@ DeclarativeCategoryRange::DeclarativeCategoryRange(QObject *parent) : { } +void DeclarativeCategoryRange::setLabel(const QString &label) +{ + auto catAxis = qobject_cast<QCategoryAxis *>(parent()); + if (catAxis) + catAxis->replaceLabel(m_label, label); + m_label = label; +} + DeclarativeCategoryAxis::DeclarativeCategoryAxis(QObject *parent) : QCategoryAxis(parent), m_labelsPosition(AxisLabelsPositionCenter) diff --git a/src/chartsqml2/declarativecategoryaxis_p.h b/src/chartsqml2/declarativecategoryaxis_p.h index 9bcd7ba8..1c1ba850 100644 --- a/src/chartsqml2/declarativecategoryaxis_p.h +++ b/src/chartsqml2/declarativecategoryaxis_p.h @@ -58,7 +58,7 @@ public: qreal endValue() { return m_endValue; } void setEndValue(qreal endValue) { m_endValue = endValue; } QString label() { return m_label; } - void setLabel(QString label) { m_label = label; } + void setLabel(const QString &label); private: qreal m_endValue; |