Changeset - 2b698ce67e65
[Not reviewed]
Hasan Yavuz ÖZDERYA - 9 years ago 2017-03-13 09:02:57
hy@ozderya.net
fixed some scaling issues
7 files changed with 88 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/mainwindow.cpp
Show inline comments
 
@@ -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");
src/plot.cpp
Show inline comments
 
/*
 
  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 <QtDebug>
 

	
 
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();
 
}
src/plot.h
Show inline comments
 
/*
 
  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;
src/plotcontrolpanel.cpp
Show inline comments
 
@@ -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<Range>();
src/plotcontrolpanel.h
Show inline comments
 
@@ -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);
 

	
src/plotmanager.cpp
Show inline comments
 
@@ -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<FrameBufferSeries*>(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;
 
    }
 
}
 

	
src/plotmanager.h
Show inline comments
 
@@ -88,6 +88,7 @@ private:
 
    bool _xAxisAsIndex;
 
    double _xMin;
 
    double _xMax;
 
    unsigned _numOfSamples;
 

	
 
    // menu actions
 
    QAction showGridAction;
0 comments (0 inline, 0 general)