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
 
@@ -212,15 +212,18 @@ MainWindow::MainWindow(QWidget *parent) 
 
    // init curve list
 
    for (unsigned int i = 0; i < numOfChannels; i++)
 
    {
 
        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");
 
    spsLabel.setToolTip("samples per second (per channel)");
 
    ui->statusBar->addPermanentWidget(&spsLabel);
 
    QObject::connect(&dataFormatPanel,
src/plot.cpp
Show inline comments
 
/*
 
  Copyright © 2015 Hasan Yavuz Özderya
 
  Copyright © 2017 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
@@ -25,12 +25,14 @@
 
#include <math.h>
 
#include <algorithm>
 

	
 
#include "plot.h"
 
#include "utils.h"
 

	
 
#include <QtDebug>
 

	
 
static const int SYMBOL_SHOW_AT_WIDTH = 5;
 
static const int SYMBOL_SIZE_MAX = 7;
 

	
 
Plot::Plot(QWidget* parent) :
 
    QwtPlot(parent),
 
    zoomer(this->canvas(), false),
 
@@ -75,13 +77,13 @@ Plot::Plot(QWidget* parent) :
 

	
 
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;
 

	
 
    if (!autoScaled)
 
    {
 
        yMin = yAxisMin;
 
@@ -89,14 +91,38 @@ void Plot::setAxis(bool autoScaled, doub
 
    }
 

	
 
    zoomer.zoom(0);
 
    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);
 
    }
 
    else
 
    {
 
@@ -105,13 +131,13 @@ void Plot::resetAxes()
 

	
 
    replot();
 
}
 

	
 
void Plot::unzoomed()
 
{
 
    setAxisAutoScale(QwtPlot::xBottom);
 
    // setAxisAutoScale(QwtPlot::xBottom);
 
    resetAxes();
 
    onXScaleChanged();
 
}
 

	
 
void Plot::showGrid(bool show)
 
{
 
@@ -270,11 +296,11 @@ void Plot::resizeEvent(QResizeEvent * ev
 
    QwtPlot::resizeEvent(event);
 
    onXScaleChanged();
 
}
 

	
 
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.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
@@ -49,13 +49,14 @@ public slots:
 
    void showGrid(bool show = true);
 
    void showMinorGrid(bool show = true);
 
    void showLegend(bool show = true);
 
    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.
 
     *
 
     * @param light show a light colored (white) animation or the opposite
 
     */
 
@@ -67,12 +68,13 @@ protected:
 
    /// update the display of symbols depending on `symbolSize`
 
    void updateSymbols();
 

	
 
private:
 
    bool isAutoScaled;
 
    double yMin, yMax;
 
    double _xMin, _xMax;
 
    int symbolSize;
 
    Zoomer zoomer;
 
    ScaleZoomer sZoomer;
 
    QwtPlotGrid grid;
 
    PlotSnapshotOverlay* snapshotOverlay;
 
    QwtPlotLegendItem legend;
src/plotcontrolpanel.cpp
Show inline comments
 
@@ -211,27 +211,42 @@ void PlotControlPanel::onAutoScaleChecke
 

	
 
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>();
 
    ui->spYmin->setValue(r.rmin);
 
    ui->spYmax->setValue(r.rmax);
 
    ui->cbAutoScale->setChecked(false);
src/plotcontrolpanel.h
Show inline comments
 
@@ -37,15 +37,18 @@ class PlotControlPanel : public QWidget
 

	
 
public:
 
    explicit PlotControlPanel(QWidget *parent = 0);
 
    ~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);
 

	
 
    /// Stores plot settings into a `QSettings`
 
    void saveSettings(QSettings* settings);
 
    /// Loads plot settings from a `QSettings`.
src/plotmanager.cpp
Show inline comments
 
@@ -37,12 +37,13 @@ PlotManager::PlotManager(QWidget* plotAr
 
{
 
    _autoScaled = true;
 
    _yMin = 0;
 
    _yMax = 1;
 
    isDemoShown = false;
 
    _infoModel = infoModel;
 
    _numOfSamples = 1;
 

	
 
    // initalize layout and single widget
 
    isMulti = false;
 
    scrollArea = NULL;
 
    setupLayout(isMulti);
 
    addPlotWidget();
 
@@ -248,13 +249,13 @@ Plot* PlotManager::addPlotWidget()
 

	
 
    plot->darkBackground(darkBackgroundAction.isChecked());
 
    plot->showGrid(showGridAction.isChecked());
 
    plot->showMinorGrid(showMinorGridAction.isChecked());
 
    plot->showLegend(showLegendAction.isChecked());
 
    plot->showDemoIndicator(isDemoShown);
 
    plot->setAxis(_autoScaled, _yMin, _yMax);
 
    plot->setYAxis(_autoScaled, _yMin, _yMax);
 

	
 
    return plot;
 
}
 

	
 
void PlotManager::addCurve(QString title, FrameBuffer* buffer)
 
{
 
@@ -410,13 +411,13 @@ void PlotManager::setYAxis(bool autoScal
 
{
 
    _autoScaled = autoScaled;
 
    _yMin = yAxisMin;
 
    _yMax = yAxisMax;
 
    for (auto plot : plotWidgets)
 
    {
 
        plot->setAxis(autoScaled, yAxisMin, yAxisMax);
 
        plot->setYAxis(autoScaled, yAxisMin, yAxisMax);
 
    }
 
}
 

	
 
void PlotManager::setXAxis(bool asIndex, double xMin, double xMax)
 
{
 
    _xAxisAsIndex = asIndex;
 
@@ -425,12 +426,23 @@ void PlotManager::setXAxis(bool asIndex,
 
    for (auto curve : curves)
 
    {
 
        // TODO: what happens when addCurve(QVector) is used?
 
        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();
 
}
 

	
 
void PlotManager::flashSnapshotOverlay()
 
{
 
    for (auto plot : plotWidgets)
 
@@ -438,15 +450,21 @@ void PlotManager::flashSnapshotOverlay()
 
        plot->flashSnapshotOverlay(darkBackgroundAction.isChecked());
 
    }
 
}
 

	
 
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;
 
    }
 
}
 

	
 
void PlotManager::saveSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_Plot);
src/plotmanager.h
Show inline comments
 
@@ -85,12 +85,13 @@ private:
 
    bool _autoScaled;
 
    double _yMin;
 
    double _yMax;
 
    bool _xAxisAsIndex;
 
    double _xMin;
 
    double _xMax;
 
    unsigned _numOfSamples;
 

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