diff --git a/src/framebufferseries.cpp b/src/framebufferseries.cpp
--- a/src/framebufferseries.cpp
+++ b/src/framebufferseries.cpp
@@ -1,5 +1,5 @@
/*
- Copyright © 2016 Hasan Yavuz Özderya
+ Copyright © 2017 Hasan Yavuz Özderya
This file is part of serialplot.
@@ -21,9 +21,19 @@
FrameBufferSeries::FrameBufferSeries(FrameBuffer* buffer)
{
+ xAsIndex = true;
+ _xmin = 0;
+ _xmax = 1;
_buffer = buffer;
}
+void FrameBufferSeries::setXAxis(bool asIndex, double xmin, double xmax)
+{
+ xAsIndex = asIndex;
+ _xmin = xmin;
+ _xmax = xmax;
+}
+
size_t FrameBufferSeries::size() const
{
return _buffer->size();
@@ -31,7 +41,14 @@ size_t FrameBufferSeries::size() const
QPointF FrameBufferSeries::sample(size_t i) const
{
- return QPointF(i, _buffer->sample(i));
+ if (xAsIndex)
+ {
+ return QPointF(i, _buffer->sample(i));
+ }
+ else
+ {
+ return QPointF(i * (_xmax - _xmin) / size() + _xmin, _buffer->sample(i));
+ }
}
QRectF FrameBufferSeries::boundingRect() const
diff --git a/src/framebufferseries.h b/src/framebufferseries.h
--- a/src/framebufferseries.h
+++ b/src/framebufferseries.h
@@ -1,5 +1,5 @@
/*
- Copyright © 2016 Hasan Yavuz Özderya
+ Copyright © 2017 Hasan Yavuz Özderya
This file is part of serialplot.
@@ -37,6 +37,9 @@ class FrameBufferSeries : public QwtSeri
public:
FrameBufferSeries(FrameBuffer* buffer);
+ /// Behavior of X axis
+ void setXAxis(bool asIndex, double xmin, double xmax);
+
// QwtSeriesData implementations
size_t size() const;
QPointF sample(size_t i) const;
@@ -44,6 +47,9 @@ public:
private:
FrameBuffer* _buffer;
+ bool xAsIndex;
+ double _xmin;
+ double _xmax;
};
#endif // FRAMEBUFFERSERIES_H
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -139,7 +139,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(&plotControlPanel, &PlotControlPanel::numOfSamplesChanged,
plotMan, &PlotManager::onNumOfSamplesChanged);
- connect(&plotControlPanel, &PlotControlPanel::scaleChanged,
+ connect(&plotControlPanel, &PlotControlPanel::yScaleChanged,
plotMan, &PlotManager::setAxis);
QObject::connect(ui->actionClear, SIGNAL(triggered(bool)),
diff --git a/src/plotcontrolpanel.cpp b/src/plotcontrolpanel.cpp
--- a/src/plotcontrolpanel.cpp
+++ b/src/plotcontrolpanel.cpp
@@ -181,7 +181,7 @@ void PlotControlPanel::onAutoScaleChecke
ui->spYmin->setEnabled(false);
ui->spYmax->setEnabled(false);
- emit scaleChanged(true); // autoscale
+ emit yScaleChanged(true); // autoscale
}
else
{
@@ -190,13 +190,13 @@ void PlotControlPanel::onAutoScaleChecke
ui->spYmin->setEnabled(true);
ui->spYmax->setEnabled(true);
- emit scaleChanged(false, ui->spYmin->value(), ui->spYmax->value());
+ emit yScaleChanged(false, ui->spYmin->value(), ui->spYmax->value());
}
}
void PlotControlPanel::onYScaleChanged()
{
- emit scaleChanged(false, ui->spYmin->value(), ui->spYmax->value());
+ emit yScaleChanged(false, ui->spYmin->value(), ui->spYmax->value());
}
bool PlotControlPanel::autoScale()
diff --git a/src/plotcontrolpanel.h b/src/plotcontrolpanel.h
--- a/src/plotcontrolpanel.h
+++ b/src/plotcontrolpanel.h
@@ -53,7 +53,7 @@ public:
signals:
void numOfSamplesChanged(int value);
- void scaleChanged(bool autoScaled, double yMin = 0, double yMax = 1);
+ void yScaleChanged(bool autoScaled, double yMin = 0, double yMax = 1);
private:
Ui::PlotControlPanel *ui;
diff --git a/src/plotcontrolpanel.ui b/src/plotcontrolpanel.ui
--- a/src/plotcontrolpanel.ui
+++ b/src/plotcontrolpanel.ui
@@ -6,7 +6,7 @@
0
0
- 590
+ 706
187
@@ -157,6 +157,87 @@
-
+
+
+ Index as X AXis
+
+
+ true
+
+
+
+ -
+
+
-
+
+
+ false
+
+
+ Xmin
+
+
+
+ -
+
+
+ false
+
+
+
+ 75
+ 0
+
+
+
+
+ 75
+ 16777215
+
+
+
+ lower limit of Y axis
+
+
+ 0.000000000000000
+
+
+
+ -
+
+
+ false
+
+
+ Xmax
+
+
+
+ -
+
+
+ false
+
+
+
+ 75
+ 16777215
+
+
+
+ upper limit of Y axis
+
+
+ 1000.000000000000000
+
+
+ 1000.000000000000000
+
+
+
+
+
+ -
Auto Scale Y Axis
@@ -166,75 +247,85 @@
- -
-
-
- false
-
-
- Ymax
-
-
+
-
+
+
-
+
+
+ false
+
+
+ Ymin
+
+
+
+ -
+
+
+ false
+
+
+
+ 75
+ 0
+
+
+
+
+ 75
+ 16777215
+
+
+
+ lower limit of Y axis
+
+
+ 0.000000000000000
+
+
+
+ -
+
+
+ false
+
+
+ Ymax
+
+
+
+ -
+
+
+ false
+
+
+
+ 75
+ 16777215
+
+
+
+ upper limit of Y axis
+
+
+ 1000.000000000000000
+
+
+ 1000.000000000000000
+
+
+
+
- -
-
-
- false
-
-
-
- 75
- 16777215
-
-
-
- upper limit of Y axis
-
-
- 1000.000000000000000
-
-
- 1000.000000000000000
-
-
-
- -
-
-
- false
-
-
- Ymin
-
-
-
- -
-
-
- false
-
-
-
- 75
- 16777215
-
-
-
- lower limit of Y axis
-
-
- 0.000000000000000
-
-
-
- -
+
-
Select Range Preset:
- -
+
-
diff --git a/src/plotmanager.cpp b/src/plotmanager.cpp
--- a/src/plotmanager.cpp
+++ b/src/plotmanager.cpp
@@ -259,7 +259,9 @@ Plot* PlotManager::addPlotWidget()
void PlotManager::addCurve(QString title, FrameBuffer* buffer)
{
auto curve = new QwtPlotCurve(title);
- curve->setSamples(new FrameBufferSeries(buffer));
+ auto series = new FrameBufferSeries(buffer);
+ series->setXAxis(false, 100, 500);
+ curve->setSamples(series);
_addCurve(curve);
}
diff --git a/src/plotmanager.h b/src/plotmanager.h
--- a/src/plotmanager.h
+++ b/src/plotmanager.h
@@ -65,7 +65,7 @@ public slots:
/// Enable display of a "DEMO" label on each plot
void showDemoIndicator(bool show = true);
/// Set the Y axis
- void setAxis(bool autoScaled, double yMin = 0, double yMax = 1);
+ void setYAxis(bool autoScaled, double yMin = 0, double yMax = 1);
/// Display an animation for snapshot
void flashSnapshotOverlay();
/// Should be called to update zoom base