Changeset - 6d13d2fee0f9
[Not reviewed]
default
0 4 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-07-23 23:11:55
hy@ozderya.net
fix unzoom with non-autoscaled axis mode
4 files changed with 22 insertions and 2 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -128,24 +128,26 @@ MainWindow::MainWindow(QWidget *parent) 
 
    for (unsigned int i = 0; i < numOfChannels; i++)
 
    {
 
        channelsData.append(DataArray(numOfSamples, 0.0));
 
        curves.append(new QwtPlotCurve());
 
        curves[i]->setSamples(dataX, channelsData[i]);
 
        curves[i]->setPen(makeColor(i));
 
        curves[i]->attach(ui->plot);
 
    }
 

	
 
    // init zoomer
 
    zoomer = new Zoomer(ui->plot->canvas(), false);
 
    zoomer->setZoomBase();
 
    QObject::connect(zoomer, &Zoomer::unzoomed,
 
                     this, &MainWindow::unzoomed);
 

	
 
    // init number format
 
    if (numberFormatButtons.checkedId() >= 0)
 
    {
 
        selectNumberFormat((NumberFormat) numberFormatButtons.checkedId());
 
    }
 
    else
 
    {
 
        selectNumberFormat(NumberFormat_uint8);
 
    }
 

	
 
    // Init sps (sample per second) counter
 
@@ -722,12 +724,27 @@ void MainWindow::messageHandler(QtMsgTyp
 
            logString = "[Fatal] " + msg;
 
            break;
 
    }
 

	
 
    ui->ptLog->appendPlainText(logString);
 
    std::cerr << logString.toStdString() << std::endl;
 

	
 
    if (type != QtDebugMsg)
 
    {
 
        ui->statusBar->showMessage(msg, 5000);
 
    }
 
}
 

	
 
void MainWindow::unzoomed()
 
{
 
    if (ui->cbAutoScale->isChecked())
 
    {
 
        ui->plot->setAxisAutoScale(QwtPlot::yLeft);
 
    }
 
    else
 
    {
 
        ui->plot->setAxisScale(QwtPlot::yLeft, ui->spYmin->value(),
 
                               ui->spYmax->value());
 
    }
 
    ui->plot->setAxisAutoScale(QwtPlot::xBottom);
 
    ui->plot->replot();
 
}
mainwindow.h
Show inline comments
 
@@ -78,24 +78,25 @@ private:
 
    unsigned int numOfSamples;
 
    unsigned int numOfChannels;
 

	
 
    QList<QwtPlotCurve*> curves;
 
    typedef QVector<double> DataArray;
 
    DataArray dataX;   // array that simply contains numbers 0..numberOfSamples
 
    QList<DataArray> channelsData;
 

	
 
    // `data` contains i th channels data
 
    void addChannelData(unsigned int channel, DataArray data);
 

	
 
    Zoomer* zoomer;
 
    void unzoomed();
 

	
 
    NumberFormat numberFormat;
 
    unsigned int sampleSize; // number of bytes in the selected number format
 
    double (MainWindow::*readSample)();
 

	
 
    // note that serialPort should already have enough bytes present
 
    template<typename T> double readSampleAs();
 

	
 
    bool skipByteRequested;
 

	
 
    const int SPS_UPDATE_TIMEOUT = 1;  // second
 
    QLabel spsLabel;
zoomer.cpp
Show inline comments
 
@@ -29,16 +29,15 @@ Zoomer::Zoomer(QWidget* widget, bool doR
 

	
 
void Zoomer::zoom(int up)
 
{
 
    if (up == +1)
 
    {
 
        this->setZoomBase(this->plot());
 
    }
 

	
 
    QwtPlotZoomer::zoom(up);
 

	
 
    if (up == 0)
 
    {
 
        this->plot()->setAxisAutoScale(QwtPlot::yLeft);
 
        this->plot()->replot();
 
        emit unzoomed();
 
    }
 
}
zoomer.h
Show inline comments
 
@@ -20,15 +20,18 @@
 
#ifndef ZOOMER_H
 
#define ZOOMER_H
 

	
 
#include <qwt_plot_zoomer.h>
 

	
 
class Zoomer : public QwtPlotZoomer
 
{
 
    Q_OBJECT
 

	
 
public:
 
    Zoomer(QWidget *, bool doReplot=true);
 
    void zoom(int up);
 

	
 
signals:
 
    void unzoomed();
 
};
 

	
 
#endif // ZOOMER_H
0 comments (0 inline, 0 general)