diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -147,6 +147,9 @@ MainWindow::MainWindow(QWidget *parent) connect(&plotControlPanel, &PlotControlPanel::xScaleChanged, plotMan, &PlotManager::setXAxis); + connect(&plotControlPanel, &PlotControlPanel::plotWidthChanged, + plotMan, &PlotManager::setPlotWidth); + QObject::connect(ui->actionClear, SIGNAL(triggered(bool)), this, SLOT(clearPlot())); @@ -222,6 +225,7 @@ MainWindow::MainWindow(QWidget *parent) plotMan->setXAxis(plotControlPanel.xAxisAsIndex(), plotControlPanel.xMin(), plotControlPanel.xMax()); plotMan->setNumOfSamples(numOfSamples); + plotMan->setPlotWidth(plotControlPanel.plotWidth()); // Init sps (sample per second) counter spsLabel.setText("0sps"); diff --git a/src/plot.cpp b/src/plot.cpp --- a/src/plot.cpp +++ b/src/plot.cpp @@ -348,3 +348,8 @@ void Plot::setNumOfSamples(unsigned valu numOfSamples = value; onXScaleChanged(); } + +void Plot::setPlotWidth(double width) +{ + zoomer.setHViewSize(width); +} diff --git a/src/plot.h b/src/plot.h --- a/src/plot.h +++ b/src/plot.h @@ -73,6 +73,8 @@ public slots: void setNumOfSamples(unsigned value); + void setPlotWidth(double width); + protected: /// update the display of symbols depending on `symbolSize` void updateSymbols(); diff --git a/src/plotcontrolpanel.cpp b/src/plotcontrolpanel.cpp --- a/src/plotcontrolpanel.cpp +++ b/src/plotcontrolpanel.cpp @@ -89,6 +89,9 @@ PlotControlPanel::PlotControlPanel(QWidg connect(ui->spXmin, SIGNAL(valueChanged(double)), this, SLOT(onXScaleChanged())); + connect(ui->spPlotWidth, SIGNAL(valueChanged(int)), + this, SLOT(onPlotWidthChanged())); + // init scale range preset list for (int nbits = 8; nbits <= 24; nbits++) // signed binary formats { @@ -275,6 +278,7 @@ void PlotControlPanel::onIndexChecked(bo emit xScaleChanged(false, ui->spXmin->value(), ui->spXmax->value()); } + emit plotWidthChanged(plotWidth()); } void PlotControlPanel::onXScaleChanged() @@ -282,9 +286,29 @@ void PlotControlPanel::onXScaleChanged() if (!xAxisAsIndex()) { emit xScaleChanged(false, ui->spXmin->value(), ui->spXmax->value()); + emit plotWidthChanged(plotWidth()); } } +double PlotControlPanel::plotWidth() const +{ + double value = ui->spPlotWidth->value(); + if (!xAxisAsIndex()) + { + // scale by xmin and xmax + auto xmax = ui->spXmax->value(); + auto xmin = ui->spXmin->value(); + double scale = (xmax - xmin) / _numOfSamples; + value *= scale; + } + return value; +} + +void PlotControlPanel::onPlotWidthChanged() +{ + emit plotWidthChanged(plotWidth()); +} + void PlotControlPanel::setChannelInfoModel(ChannelInfoModel* model) { ui->tvChannelInfo->setModel(model); diff --git a/src/plotcontrolpanel.h b/src/plotcontrolpanel.h --- a/src/plotcontrolpanel.h +++ b/src/plotcontrolpanel.h @@ -46,6 +46,7 @@ public: bool xAxisAsIndex() const; double xMax() const; double xMin() const; + double plotWidth() const; void setChannelInfoModel(ChannelInfoModel* model); @@ -58,6 +59,7 @@ signals: void numOfSamplesChanged(int value); void yScaleChanged(bool autoScaled, double yMin = 0, double yMax = 1); void xScaleChanged(bool asIndex, double xMin = 0, double xMax = 1); + void plotWidthChanged(double width); private: Ui::PlotControlPanel *ui; @@ -80,6 +82,7 @@ private slots: void onRangeSelected(); void onIndexChecked(bool checked); void onXScaleChanged(); + void onPlotWidthChanged(); }; #endif // PLOTCONTROLPANEL_H diff --git a/src/plotcontrolpanel.ui b/src/plotcontrolpanel.ui --- a/src/plotcontrolpanel.ui +++ b/src/plotcontrolpanel.ui @@ -7,7 +7,7 @@ 0 0 706 - 187 + 195 @@ -132,15 +132,24 @@ + + + - Number Of Samples: + Buffer Size: + + + 80 + 0 + + - length of X axis + Length of acquisition as number of samples false @@ -156,7 +165,7 @@ - + Index as X AXis @@ -166,7 +175,7 @@ - + @@ -237,7 +246,7 @@ - + Auto Scale Y Axis @@ -247,7 +256,7 @@ - + @@ -318,16 +327,51 @@ - + Select Range Preset: - + + + + + + + + Plot Width: + + + + + + + + 80 + 0 + + + + Width of X axis as maximum number of samples that are shown in plot + + + false + + + 2 + + + 100000 + + + 1000 + + + diff --git a/src/plotmanager.cpp b/src/plotmanager.cpp --- a/src/plotmanager.cpp +++ b/src/plotmanager.cpp @@ -542,6 +542,15 @@ void PlotManager::setNumOfSamples(unsign } } +void PlotManager::setPlotWidth(double width) +{ + _plotWidth = width; + for (auto plot : plotWidgets) + { + plot->setPlotWidth(width); + } +} + PlotViewSettings PlotManager::viewSettings() const { return PlotViewSettings( diff --git a/src/plotmanager.h b/src/plotmanager.h --- a/src/plotmanager.h +++ b/src/plotmanager.h @@ -88,6 +88,8 @@ public slots: void flashSnapshotOverlay(); /// Should be called to update zoom base void setNumOfSamples(unsigned value); + /// Maximum width of X axis (limit of hscroll) + void setPlotWidth(double width); private: bool isMulti; @@ -106,6 +108,7 @@ private: double _xMin; double _xMax; unsigned _numOfSamples; + double _plotWidth; Plot::ShowSymbols showSymbols; // menu actions diff --git a/src/scrollzoomer.cpp b/src/scrollzoomer.cpp --- a/src/scrollzoomer.cpp +++ b/src/scrollzoomer.cpp @@ -70,12 +70,12 @@ void ScrollZoomer::setXLimits(double min xMin = min; xMax = max; setZoomBase(); - // TODO: should we update zoom base here? } void ScrollZoomer::setHViewSize(double size) { hViewSize = size; + setZoomBase(); } void ScrollZoomer::setZoomBase(bool doReplot)