From e0b267cfb7c5f6ee84e66c52efb4dffb0c750984 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 7 Oct 2019 17:49:59 +0300 Subject: Pass CategoryRange label change to parent QCategoryAxis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: QTBUG-78439 Change-Id: I1c0de505c73ea42e67947fed91a535a117a2ad5b Reviewed-by: Mahmoud Badri Reviewed-by: Tomi Korpipää --- src/chartsqml2/declarativecategoryaxis.cpp | 8 ++++++++ src/chartsqml2/declarativecategoryaxis_p.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) 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(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; -- cgit v1.2.3 From e757445355dbb3f3001fae49bb72113d7a52173d Mon Sep 17 00:00:00 2001 From: Tomi Korpipaa Date: Wed, 9 Oct 2019 09:26:39 +0300 Subject: Fix trackpad scrolling on macOS Task-number: QTBUG-77403 Change-Id: I8c6431412ba4b554affa69578b1c2ca3e08c7a7f Reviewed-by: Miikka Heikkinen --- src/charts/qchartview.cpp | 11 +++++++++++ src/charts/qchartview.h | 13 +++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) 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 d_ptr; -- cgit v1.2.3 From 289b9904a7c9ce241896f65509a19d0213def35c Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Thu, 10 Oct 2019 11:27:32 +0300 Subject: Round adjustedMin for offset value in ChartBarCategoryAxis Using qCeil(adjustedMin) to calculate the offset caused some labels to be trimmed, rounding the value is more appropriate. Task-number: QTBUG-62230 Change-Id: I2c7c09ae50f8a4f4958653fa557159962da9a8a2 Reviewed-by: Miikka Heikkinen --- src/charts/axis/barcategoryaxis/chartbarcategoryaxisx.cpp | 4 ++-- src/charts/axis/barcategoryaxis/chartbarcategoryaxisy.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 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 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& 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 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& 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 { -- cgit v1.2.3 From a692d9a826d864e91b668415aea266228c2ae323 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Fri, 11 Oct 2019 09:18:12 +0300 Subject: Draw points that lie inside the chart rect only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only drawback of this approach is that if the pen has a transparent color, the overlap between a point and the graph line below it is clear. But it wasn't perfect anyway before this patch. The impact of this approach on performance is minimal. Task-number: QTBUG-62839 Change-Id: I4478d9136fe7ca1a1c6bf5dd5a3f459af63b953c Reviewed-by: Tomi Korpipää Reviewed-by: Miikka Heikkinen --- src/charts/linechart/linechartitem.cpp | 40 ++++++++++++++-------------------- 1 file changed, 16 insertions(+), 24 deletions(-) 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) -- cgit v1.2.3 From 73f81ac479eb5ce48716c491abfe7a875a047edb Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 14 Oct 2019 13:40:14 +0300 Subject: Fix removing rows from candlestick model mapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no guarantee removed rows are in correct order or that they are sequential, so don't assume so. Fixes: QTBUG-79188 Change-Id: I6ee6851ce881872d01486c600d4204faeb162d87 Reviewed-by: Tomi Korpipää --- .../candlestickchart/qcandlestickmodelmapper.cpp | 33 ++++++++++++++++------ .../tst_qcandlestickmodelmapper.cpp | 11 +++++++- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/charts/candlestickchart/qcandlestickmodelmapper.cpp b/src/charts/candlestickchart/qcandlestickmodelmapper.cpp index 8f876cd3..95a53b52 100644 --- a/src/charts/candlestickchart/qcandlestickmodelmapper.cpp +++ b/src/charts/candlestickchart/qcandlestickmodelmapper.cpp @@ -33,6 +33,8 @@ #include #include +#include + QT_CHARTS_BEGIN_NAMESPACE /*! @@ -590,20 +592,33 @@ void QCandlestickModelMapperPrivate::candlestickSetsRemoved(const QList removedIndices; + for (auto &set : sets) { + int index = m_sets.indexOf(set); + if (index != -1) + removedIndices << index; + } + + if (removedIndices.isEmpty()) return; - m_lastSetSection -= sets.count(); + std::sort(removedIndices.begin(), removedIndices.end()); - for (int i = firstIndex + sets.count() - 1; i >= firstIndex; --i) - m_sets.removeAt(i); + for (int i = removedIndices.size() - 1; i >= 0; --i) { + m_sets.removeAt(removedIndices[i]); + --m_lastSetSection; + } blockModelSignals(); - if (q->orientation() == Qt::Vertical) - m_model->removeColumns(firstIndex + m_firstSetSection, sets.count()); - else - m_model->removeRows(firstIndex + m_firstSetSection, sets.count()); + + // There is no guarantee removed sets are continuous, so remove them one by one + for (int i = removedIndices.size() - 1; i >= 0; --i) { + if (q->orientation() == Qt::Vertical) + m_model->removeColumns(removedIndices[i] + m_firstSetSection, 1); + else + m_model->removeRows(removedIndices[i] + m_firstSetSection, 1); + } + blockModelSignals(false); initializeCandlestickFromModel(); } diff --git a/tests/auto/qcandlestickmodelmapper/tst_qcandlestickmodelmapper.cpp b/tests/auto/qcandlestickmodelmapper/tst_qcandlestickmodelmapper.cpp index cf3531ed..a9ac4837 100644 --- a/tests/auto/qcandlestickmodelmapper/tst_qcandlestickmodelmapper.cpp +++ b/tests/auto/qcandlestickmodelmapper/tst_qcandlestickmodelmapper.cpp @@ -425,14 +425,23 @@ void tst_qcandlestickmodelmapper::seriesUpdated() QList newCandlestickSets; newCandlestickSets << new QCandlestickSet(3.0, 5.0, 2.0, 4.0, 1234); newCandlestickSets << new QCandlestickSet(5.0, 7.0, 4.0, 6.0, 5678); + newCandlestickSets << new QCandlestickSet(3.0, 8.0, 4.0, 6.0, 6789); m_series->append(newCandlestickSets); QCOMPARE(m_model->columnCount(), m_modelColumnCount + newCandlestickSets.count()); // remove sets newCandlestickSets.clear(); newCandlestickSets << m_series->sets().at(m_series->count() - 1); - newCandlestickSets << m_series->sets().at(m_series->count() - 2); + newCandlestickSets << m_series->sets().at(m_series->count() - 5); + newCandlestickSets << m_series->sets().at(m_series->count() - 3); m_series->remove(newCandlestickSets); + + // Make sure correct rows have been removed from model + for (int i = 0, end = m_series->sets().size(); i < end; ++i) { + QCOMPARE(m_model->data(m_model->index(m_vMapper->timestampRow(), i)).toReal(), + m_series->sets().at(i)->timestamp()); + } + QCOMPARE(m_model->columnCount(), m_modelColumnCount); } -- cgit v1.2.3 From fe9066461afd36fc9611db11f95f4c43f645b96e Mon Sep 17 00:00:00 2001 From: Timo Aarnipuro Date: Tue, 15 Oct 2019 12:03:50 +0300 Subject: Add dependency to texthtmlparser EditableAxisLabel uses QTextDocument::setHtml, which is only available if texthtmlparser is enabled. Change-Id: I1ef5ec101b79a173bb1ece1fe41d41a5b30bef0a Reviewed-by: Miikka Heikkinen Reviewed-by: Mahmoud Badri --- qtcharts.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/qtcharts.pro b/qtcharts.pro index fc2928f8..b5f519dc 100644 --- a/qtcharts.pro +++ b/qtcharts.pro @@ -3,6 +3,7 @@ requires(qtHaveModule(widgets)) qtHaveModule(widgets) { QT_FOR_CONFIG += widgets requires(qtConfig(graphicsview)) + requires(qtConfig(texthtmlparser)) } load(qt_parts) -- cgit v1.2.3