diff --git a/src/ui/designer/QGCXYPlot.cc b/src/ui/designer/QGCXYPlot.cc index 992a7154844fad34ede0f9a489c56c840a0fcf6c..a258feedf2cda0cb59503b85e558c7eb654bef1e 100644 --- a/src/ui/designer/QGCXYPlot.cc +++ b/src/ui/designer/QGCXYPlot.cc @@ -33,23 +33,28 @@ public: /** Append data, returning the number of removed items */ int appendData(const QPointF &data) { - if(!minMaxSet) { + m_data.append(data); + int removed = 0; + while (m_data.size() > m_maxShowPoints) { + ++removed; + m_data.removeFirst(); + } + if (!minMaxSet) { xmin = xmax = data.x(); ymin = ymax = data.y(); minMaxSet = true; - } else if(m_autoScale) { - xmin = qMin(qreal(xmin), data.x()); + previousTime =xmin; + } else if (m_autoScale) { + if (m_autoScaleTime) { + xmin += removed * (data.x() - previousTime); + previousTime = data.x(); + } else { + xmin = qMin(qreal(xmin), data.x()); + } xmax = qMax(qreal(xmax), data.x()); ymin = qMin(qreal(ymin), data.y()); ymax = qMax(qreal(ymax), data.y()); } - - m_data.append(data); - int removed = 0; - while(m_data.size() > m_maxStorePoints) { - ++removed; - m_data.removeFirst(); - } itemChanged(); return removed; } @@ -61,6 +66,10 @@ public: void setColor(const QColor &color) { m_color = color; } + void setTimeSerie(bool state) { + clear(); + m_autoScaleTime = state; + } void unsetMinMax() { if(m_autoScale) return; @@ -70,7 +79,7 @@ public: minMaxSet = false; else { minMaxSet = true; - xmax = xmin = m_data.at(0).x(); + previousTime = xmax = xmin = m_data.at(0).x(); ymax = ymin = m_data.at(0).y(); for(int i = 1; i < m_data.size(); i++) { xmin = qMin(qreal(xmin), m_data.at(i).x()); @@ -164,12 +173,14 @@ private: int m_smoothPoints; /** Number of points to average across */ mutable QColor m_color; + double previousTime; double xmin; double xmax; double ymin; double ymax; bool minMaxSet; bool m_autoScale; + bool m_autoScaleTime; int m_startIndex; }; @@ -220,6 +231,7 @@ QGCXYPlot::QGCXYPlot(QWidget *parent) : connect(ui->minY, SIGNAL(valueChanged(double)),this, SLOT(updateMinMaxSettings())); connect(ui->maxY, SIGNAL(valueChanged(double)),this, SLOT(updateMinMaxSettings())); connect(ui->automaticAxisRange, SIGNAL(toggled(bool)),this, SLOT(updateMinMaxSettings())); + connect(ui->timeAxisRange, SIGNAL(toggled(bool)),this, SLOT(setTimeAxis())); connect(ui->maxDataShowSpinBox, SIGNAL(valueChanged(int)),this, SLOT(updateMinMaxSettings())); connect(ui->maxDataStoreSpinBox, SIGNAL(valueChanged(int)),this, SLOT(updateMinMaxSettings())); connect(ui->smoothSpinBox, SIGNAL(valueChanged(int)),this, SLOT(updateMinMaxSettings())); @@ -261,6 +273,7 @@ void QGCXYPlot::setEditMode(bool editMode) ui->maxDataShowSpinBox->setVisible(editMode); ui->maxDataStoreSpinBox->setVisible(editMode); ui->automaticAxisRange->setVisible(editMode); + ui->timeAxisRange->setVisible(editMode); ui->lblSmooth->setVisible(editMode); ui->smoothSpinBox->setVisible(editMode); @@ -286,7 +299,7 @@ void QGCXYPlot::writeSettings(QSettings& settings) settings.setValue("QGC_XYPLOT_MAXDATA_SHOW", ui->maxDataShowSpinBox->value()); settings.setValue("QGC_XYPLOT_AUTO", ui->automaticAxisRange->isChecked()); settings.setValue("QGC_XYPLOT_SMOOTH", ui->smoothSpinBox->value()); - + settings.setValue("QGC_XYPLOT_TIME", ui->timeAxisRange->isChecked()); settings.sync(); } void QGCXYPlot::readSettings(const QString& pre,const QVariantMap& settings) @@ -301,6 +314,7 @@ void QGCXYPlot::readSettings(const QString& pre,const QVariantMap& settings) ui->maxDataStoreSpinBox->setValue(settings.value(pre + "QGC_XYPLOT_MAXDATA_STORE", 10000).toInt()); ui->maxDataShowSpinBox->setValue(settings.value(pre + "QGC_XYPLOT_MAXDATA_SHOW", 15).toInt()); ui->smoothSpinBox->setValue(settings.value(pre + "QGC_XYPLOT_SMOOTH", 1).toInt()); + ui->timeAxisRange->setChecked(settings.value(pre + "QGC_XYPLOT_TIME", true).toBool()); plot->setAxisTitle(QwtPlot::xBottom, ui->editXParam->currentText()); plot->setAxisTitle(QwtPlot::yLeft, ui->editYParam->currentText()); updateMinMaxSettings(); @@ -318,6 +332,7 @@ void QGCXYPlot::readSettings(const QSettings& settings) ui->maxDataStoreSpinBox->setValue(settings.value("QGC_XYPLOT_MAXDATA_STORE", 10000).toInt()); ui->maxDataShowSpinBox->setValue(settings.value("QGC_XYPLOT_MAXDATA_SHOW", 15).toInt()); ui->smoothSpinBox->setValue(settings.value("QGC_XYPLOT_SMOOTH", 1).toInt()); + ui->timeAxisRange->setChecked(settings.value("QGC_XYPLOT_TIME", true).toBool()); plot->setAxisTitle(QwtPlot::xBottom, ui->editXParam->currentText()); plot->setAxisTitle(QwtPlot::yLeft, ui->editYParam->currentText()); updateMinMaxSettings(); @@ -412,6 +427,11 @@ void QGCXYPlot::updateMinMaxSettings() xycurve->setSmoothPoints(ui->smoothSpinBox->value()); } +void QGCXYPlot::setTimeAxis() +{ + xycurve->setTimeSerie(ui->timeAxisRange->isChecked()); +} + void QGCXYPlot::on_maxDataShowSpinBox_valueChanged(int value) { ui->maxDataStoreSpinBox->setMinimum(value); diff --git a/src/ui/designer/QGCXYPlot.h b/src/ui/designer/QGCXYPlot.h index 1b4818d8899d579f94148020f07bd2b59ce4c3cc..d574f2ee4da25f28eec355ace2d4b3d72744b053 100644 --- a/src/ui/designer/QGCXYPlot.h +++ b/src/ui/designer/QGCXYPlot.h @@ -31,10 +31,11 @@ public slots: void styleChanged(MainWindow::QGC_MAINWINDOW_STYLE style); void updateMinMaxSettings(); + private slots: void on_maxDataShowSpinBox_valueChanged(int value); void on_stopStartButton_toggled(bool checked); - + void setTimeAxis(); void on_timeScrollBar_valueChanged(int value); private: @@ -42,6 +43,7 @@ private: QwtPlot *plot; XYPlotCurve* xycurve; + bool autoScaleTime; double x; /**< Last unused value for the x-coordinate */ quint64 x_timestamp_us; /**< Timestamp that we last recieved a value for x */ bool x_valid; /**< Whether we have recieved an x value but so far no corresponding y value */