# HG changeset patch # User Hasan Yavuz ÖZDERYA # Date 2017-03-13 09:02:57 # Node ID 2b698ce67e65ebbd30cd01fa6571f18e3d52d97e # Parent fca00b767effd612cabf909a2e8357b3e7c75a58 fixed some scaling issues diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -215,9 +215,12 @@ MainWindow::MainWindow(QWidget *parent) plotMan->addCurve(channelMan.channelName(i), channelMan.channelBuffer(i)); } - // init auto scale + // init scales plotMan->setYAxis(plotControlPanel.autoScale(), plotControlPanel.yMin(), plotControlPanel.yMax()); + plotMan->setXAxis(plotControlPanel.xAxisAsIndex(), + plotControlPanel.xMin(), plotControlPanel.xMax()); + plotMan->onNumOfSamplesChanged(numOfSamples); // 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 @@ -1,5 +1,5 @@ /* - Copyright © 2015 Hasan Yavuz Özderya + Copyright © 2017 Hasan Yavuz Özderya This file is part of serialplot. @@ -28,6 +28,8 @@ #include "plot.h" #include "utils.h" +#include + static const int SYMBOL_SHOW_AT_WIDTH = 5; static const int SYMBOL_SIZE_MAX = 7; @@ -78,7 +80,7 @@ Plot::~Plot() if (snapshotOverlay != NULL) delete snapshotOverlay; } -void Plot::setAxis(bool autoScaled, double yAxisMin, double yAxisMax) +void Plot::setYAxis(bool autoScaled, double yAxisMin, double yAxisMax) { this->isAutoScaled = autoScaled; @@ -92,8 +94,32 @@ void Plot::setAxis(bool autoScaled, doub resetAxes(); } +void Plot::setXAxis(double xMin, double xMax) +{ + qDebug() << "setXAxis:" << xMin << xMax; + _xMin = xMin; + _xMax = xMax; + + zoomer.zoom(0); // unzoom + + // set axis + setAxisScale(QwtPlot::xBottom, xMin, xMax); + + // reset zoom base + auto base = zoomer.zoomBase(); + base.setLeft(xMin); + base.setRight(xMax); + zoomer.setZoomBase(base); + + qDebug() << "base:" << base; + + onXScaleChanged(); + replot(); +} + void Plot::resetAxes() { + // reset y axis if (isAutoScaled) { setAxisAutoScale(QwtPlot::yLeft); @@ -108,7 +134,7 @@ void Plot::resetAxes() void Plot::unzoomed() { - setAxisAutoScale(QwtPlot::xBottom); + // setAxisAutoScale(QwtPlot::xBottom); resetAxes(); onXScaleChanged(); } @@ -273,8 +299,8 @@ void Plot::resizeEvent(QResizeEvent * ev void Plot::onNumOfSamplesChanged(unsigned value) { - auto currentBase = zoomer.zoomBase(); - currentBase.setWidth(value); - zoomer.setZoomBase(currentBase); - onXScaleChanged(); + // auto currentBase = zoomer.zoomBase(); + // currentBase.setWidth(value); + // zoomer.setZoomBase(currentBase); + // onXScaleChanged(); } diff --git a/src/plot.h b/src/plot.h --- a/src/plot.h +++ b/src/plot.h @@ -1,5 +1,5 @@ /* - Copyright © 2016 Hasan Yavuz Özderya + Copyright © 2017 Hasan Yavuz Özderya This file is part of serialplot. @@ -52,7 +52,8 @@ public slots: void showDemoIndicator(bool show = true); void unzoom(); void darkBackground(bool enabled = true); - void setAxis(bool autoScaled, double yMin = 0, double yMax = 1); + void setYAxis(bool autoScaled, double yMin = 0, double yMax = 1); + void setXAxis(double xMin, double xMax); /** * Displays an animation for snapshot. @@ -70,6 +71,7 @@ protected: private: bool isAutoScaled; double yMin, yMax; + double _xMin, _xMax; int symbolSize; Zoomer zoomer; ScaleZoomer sZoomer; diff --git a/src/plotcontrolpanel.cpp b/src/plotcontrolpanel.cpp --- a/src/plotcontrolpanel.cpp +++ b/src/plotcontrolpanel.cpp @@ -214,21 +214,36 @@ void PlotControlPanel::onYScaleChanged() emit yScaleChanged(false, ui->spYmin->value(), ui->spYmax->value()); } -bool PlotControlPanel::autoScale() +bool PlotControlPanel::autoScale() const { return ui->cbAutoScale->isChecked(); } -double PlotControlPanel::yMax() +double PlotControlPanel::yMax() const { return ui->spYmax->value(); } -double PlotControlPanel::yMin() +double PlotControlPanel::yMin() const { return ui->spYmin->value(); } +bool PlotControlPanel::xAxisAsIndex() const +{ + return ui->cbIndex->isChecked(); +} + +double PlotControlPanel::xMax() const +{ + return ui->spXmax->value(); +} + +double PlotControlPanel::xMin() const +{ + return ui->spXmin->value(); +} + void PlotControlPanel::onRangeSelected() { Range r = ui->cbRangePresets->currentData().value(); diff --git a/src/plotcontrolpanel.h b/src/plotcontrolpanel.h --- a/src/plotcontrolpanel.h +++ b/src/plotcontrolpanel.h @@ -40,9 +40,12 @@ public: ~PlotControlPanel(); unsigned numOfSamples(); - bool autoScale(); - double yMax(); - double yMin(); + bool autoScale() const; + double yMax() const; + double yMin() const; + bool xAxisAsIndex() const; + double xMax() const; + double xMin() const; void setChannelInfoModel(ChannelInfoModel* model); diff --git a/src/plotmanager.cpp b/src/plotmanager.cpp --- a/src/plotmanager.cpp +++ b/src/plotmanager.cpp @@ -40,6 +40,7 @@ PlotManager::PlotManager(QWidget* plotAr _yMax = 1; isDemoShown = false; _infoModel = infoModel; + _numOfSamples = 1; // initalize layout and single widget isMulti = false; @@ -251,7 +252,7 @@ Plot* PlotManager::addPlotWidget() plot->showMinorGrid(showMinorGridAction.isChecked()); plot->showLegend(showLegendAction.isChecked()); plot->showDemoIndicator(isDemoShown); - plot->setAxis(_autoScaled, _yMin, _yMax); + plot->setYAxis(_autoScaled, _yMin, _yMax); return plot; } @@ -413,7 +414,7 @@ void PlotManager::setYAxis(bool autoScal _yMax = yAxisMax; for (auto plot : plotWidgets) { - plot->setAxis(autoScaled, yAxisMin, yAxisMax); + plot->setYAxis(autoScaled, yAxisMin, yAxisMax); } } @@ -428,6 +429,17 @@ void PlotManager::setXAxis(bool asIndex, FrameBufferSeries* series = static_cast(curve->data()); series->setXAxis(asIndex, xMin, xMax); } + for (auto plot : plotWidgets) + { + if (asIndex) + { + plot->setXAxis(0, _numOfSamples); + } + else + { + plot->setXAxis(xMin, xMax); + } + } replot(); } @@ -441,9 +453,15 @@ void PlotManager::flashSnapshotOverlay() void PlotManager::onNumOfSamplesChanged(unsigned value) { - for (auto plot : plotWidgets) + _numOfSamples = value; + if (_xAxisAsIndex) { - plot->onNumOfSamplesChanged(value); + for (auto plot : plotWidgets) + { + // plot->onNumOfSamplesChanged(value); + plot->setXAxis(0, value); + } + qDebug() << "_xAxisAsIndex" << value; } } diff --git a/src/plotmanager.h b/src/plotmanager.h --- a/src/plotmanager.h +++ b/src/plotmanager.h @@ -88,6 +88,7 @@ private: bool _xAxisAsIndex; double _xMin; double _xMax; + unsigned _numOfSamples; // menu actions QAction showGridAction;