From 85017a1309218d00035de1e2eda665bcde8cd91d Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 8 Jan 2014 16:34:10 -0800 Subject: [PATCH] Fix -Werror=type-limits --- src/ui/designer/QGCXYPlot.cc | 34 +++++++++++++++++++++------------- src/ui/designer/QGCXYPlot.h | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/ui/designer/QGCXYPlot.cc b/src/ui/designer/QGCXYPlot.cc index 58fcb0e..079e27e 100644 --- a/src/ui/designer/QGCXYPlot.cc +++ b/src/ui/designer/QGCXYPlot.cc @@ -362,19 +362,27 @@ void QGCXYPlot::appendData(int uasId, const QString& curve, const QString& unit, } else return; - if(x_valid && y_valid && (int)qAbs(y_timestamp_us - x_timestamp_us) <= max_timestamp_diff_us) { - int removed = xycurve->appendData( QPointF(x,y) ); - x_valid = false; - y_valid = false; - bool atMaximum = (ui->timeScrollBar->value() == ui->timeScrollBar->maximum()); - if(ui->timeScrollBar->maximum() != xycurve->dataSize()) { - ui->timeScrollBar->setMaximum(xycurve->dataSize()); - if(atMaximum) - ui->timeScrollBar->setValue(ui->timeScrollBar->maximum()); - } else if(!atMaximum) { //Move the scrollbar to keep current value selected - int value = qMax(ui->timeScrollBar->minimum(), ui->timeScrollBar->value() - removed); - ui->timeScrollBar->setValue(value); - xycurve->setStartIndex(value); + if(x_valid && y_valid) { + quint64 difference; + if (y_timestamp_us < x_timestamp_us) { + difference = x_timestamp_us - y_timestamp_us; + } else { + difference = y_timestamp_us - x_timestamp_us; + } + if (difference <= max_timestamp_diff_us) { + int removed = xycurve->appendData( QPointF(x,y) ); + x_valid = false; + y_valid = false; + bool atMaximum = (ui->timeScrollBar->value() == ui->timeScrollBar->maximum()); + if(ui->timeScrollBar->maximum() != xycurve->dataSize()) { + ui->timeScrollBar->setMaximum(xycurve->dataSize()); + if(atMaximum) + ui->timeScrollBar->setValue(ui->timeScrollBar->maximum()); + } else if(!atMaximum) { //Move the scrollbar to keep current value selected + int value = qMax(ui->timeScrollBar->minimum(), ui->timeScrollBar->value() - removed); + ui->timeScrollBar->setValue(value); + xycurve->setStartIndex(value); + } } } } diff --git a/src/ui/designer/QGCXYPlot.h b/src/ui/designer/QGCXYPlot.h index 77159d6..1b4818d 100644 --- a/src/ui/designer/QGCXYPlot.h +++ b/src/ui/designer/QGCXYPlot.h @@ -48,7 +48,7 @@ private: double y; /**< Last unused value for the x-coordinate */ quint64 y_timestamp_us; /**< Timestamp that we last recieved a value for x */ bool y_valid; /**< Whether we have recieved an x value but so far no corresponding y value */ - int max_timestamp_diff_us; /**< Only combine x and y to a data point if the timestamp for both doesn't differ by more than this */ + quint64 max_timestamp_diff_us; /**< Only combine x and y to a data point if the timestamp for both doesn't differ by more than this */ }; #endif // QGCXYPLOT_H