summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2019-10-16 11:43:01 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2019-10-16 11:43:01 +0200
commita6f81dd33f2449437a16d841af1ff3acf6eb09a6 (patch)
tree597f933752c4ffc2c9c8079e1a1e0e595e4bb39f
parent1b0c37d29ae8775681b968d289d3f8e649178e5b (diff)
parent4b534d99fe687c40fb9dd08de6b4f7ebadfb9135 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
-rw-r--r--qtcharts.pro1
-rw-r--r--src/charts/axis/barcategoryaxis/chartbarcategoryaxisx.cpp4
-rw-r--r--src/charts/axis/barcategoryaxis/chartbarcategoryaxisy.cpp4
-rw-r--r--src/charts/candlestickchart/qcandlestickmodelmapper.cpp33
-rw-r--r--src/charts/linechart/linechartitem.cpp40
-rw-r--r--src/charts/qchartview.cpp11
-rw-r--r--src/charts/qchartview.h13
-rw-r--r--src/chartsqml2/declarativecategoryaxis.cpp8
-rw-r--r--src/chartsqml2/declarativecategoryaxis_p.h2
-rw-r--r--tests/auto/qcandlestickmodelmapper/tst_qcandlestickmodelmapper.cpp11
10 files changed, 84 insertions, 43 deletions
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)
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/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 <QtCore/QAbstractItemModel>
#include <private/qcandlestickmodelmapper_p.h>
+#include <algorithm>
+
QT_CHARTS_BEGIN_NAMESPACE
/*!
@@ -590,20 +592,33 @@ void QCandlestickModelMapperPrivate::candlestickSetsRemoved(const QList<QCandles
if (sets.isEmpty())
return;
- int firstIndex = m_sets.indexOf(sets.at(0));
- if (firstIndex == -1)
+ QVector<int> 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/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;
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<QCandlestickSet *> 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);
}