summaryrefslogtreecommitdiffstats
path: root/src/charts/xychart
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2016-08-04 15:17:50 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2016-08-05 12:36:53 +0000
commit704fe5cb96d56088b34aceec723c9b16e67f6a8a (patch)
tree6768d5d272672b1f6a162b21f7c571d59a9e22ba /src/charts/xychart
parent2c405ae0278b47b2227f85337030973786d63286 (diff)
Print console warning when invalid row/column used in model mapper
Task-number: QTBUG-52654 Change-Id: I37fac883307409da349c1923c0e295caa9cf6f8a Reviewed-by: Mika Salmela <mika.salmela@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/charts/xychart')
-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 3f87d908..f51703b0 100644
--- a/src/charts/xychart/qxymodelmapper.cpp
+++ b/src/charts/xychart/qxymodelmapper.cpp
@@ -24,6 +24,7 @@
#include <QtCharts/QXYSeries>
#include <QtCore/QAbstractItemModel>
#include <QtCore/QDateTime>
+#include <QtCore/QDebug>
QT_CHARTS_BEGIN_NAMESPACE
@@ -536,15 +537,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);
}