summaryrefslogtreecommitdiffstats
path: root/src/charts/xychart/qxymodelmapper.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-08-10 17:48:55 +0200
committerLiang Qi <liang.qi@qt.io>2016-08-11 09:00:45 +0200
commita7b80c0b6176692ee2b7abdce7acdc5c37a72d00 (patch)
tree6d4835511c823e1ebff312869e51c9ff949f85ad /src/charts/xychart/qxymodelmapper.cpp
parentc121fb4ad00bc9617a011e040ef5ed695610a504 (diff)
parent64d931d5fc5f17b8c4875f6c59f900aa59080881 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: src/charts/glwidget.cpp src/charts/xychart/glxyseriesdata_p.h src/chartsqml2/declarativerendernode.cpp Change-Id: I611ff3a7874ceb7dddcf0f4d069927a9899a986d
Diffstat (limited to 'src/charts/xychart/qxymodelmapper.cpp')
-rw-r--r--src/charts/xychart/qxymodelmapper.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/charts/xychart/qxymodelmapper.cpp b/src/charts/xychart/qxymodelmapper.cpp
index b6037858..3b2ccd83 100644
--- a/src/charts/xychart/qxymodelmapper.cpp
+++ b/src/charts/xychart/qxymodelmapper.cpp
@@ -32,6 +32,7 @@
#include <QtCharts/QXYSeries>
#include <QtCore/QAbstractItemModel>
#include <QtCore/QDateTime>
+#include <QtCore/QDebug>
QT_CHARTS_BEGIN_NAMESPACE
@@ -544,15 +545,27 @@ void QXYModelMapperPrivate::initializeXYFromModel()
int pointPos = 0;
QModelIndex xIndex = xModelIndex(pointPos);
QModelIndex yIndex = yModelIndex(pointPos);
- while (xIndex.isValid() && yIndex.isValid()) {
- QPointF point;
- point.setX(valueFromModel(xIndex));
- point.setY(valueFromModel(yIndex));
- m_series->append(point);
- pointPos++;
- xIndex = xModelIndex(pointPos);
- yIndex = yModelIndex(pointPos);
+
+ if (xIndex.isValid() && yIndex.isValid()) {
+ while (xIndex.isValid() && yIndex.isValid()) {
+ QPointF point;
+ point.setX(valueFromModel(xIndex));
+ point.setY(valueFromModel(yIndex));
+ m_series->append(point);
+ pointPos++;
+ xIndex = xModelIndex(pointPos);
+ yIndex = yModelIndex(pointPos);
+ // Don't warn about invalid index after the first, those are valid and used to
+ // determine when we should end looping.
+ }
+ } else {
+ // Invalid index right off the bat means series will be left empty, so output a warning
+ if (!xIndex.isValid())
+ qWarning() << __FUNCTION__ << QStringLiteral("Invalid X coordinate index in model mapper.");
+ else if (!yIndex.isValid())
+ qWarning() << __FUNCTION__ << QStringLiteral("Invalid Y coordinate index in model mapper.");
}
+
blockSeriesSignals(false);
}