# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2015-03-08 17:15:46 # Node ID 90fb38350cfde10b665c9e3935732c5486a7e7d1 # Parent 799dda1bc58478eefddea6a7653850e7fbf09a75 implemented plot axis limit controls diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,7 +2,8 @@ #include "ui_mainwindow.h" #include #include - +#include +#include #include "utils.h" MainWindow::MainWindow(QWidget *parent) : @@ -35,6 +36,15 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(ui->spNumOfSamples, SELECT::OVERLOAD_OF(&QSpinBox::valueChanged), this, &MainWindow::onNumOfSamplesChanged); + QObject::connect(ui->cbAutoScale, &QCheckBox::toggled, + this, &MainWindow::onAutoScaleChecked); + + QObject::connect(ui->spYmin, SIGNAL(valueChanged(double)), + this, SLOT(onYScaleChanged())); + + QObject::connect(ui->spYmax, SIGNAL(valueChanged(double)), + this, SLOT(onYScaleChanged())); + // init port signals QObject::connect(&(this->serialPort), SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(onPortError(QSerialPort::SerialPortError))); @@ -43,6 +53,13 @@ MainWindow::MainWindow(QWidget *parent) loadBaudRateList(); ui->cbBaudRate->setCurrentIndex(ui->cbBaudRate->findText("9600")); + // set limits for axis limit boxes + ui->spYmin->setRange(std::numeric_limits::min(), + std::numeric_limits::max()); + + ui->spYmax->setRange(std::numeric_limits::min(), + std::numeric_limits::max()); + // init plot numOfSamples = ui->spNumOfSamples->value(); dataArray.resize(numOfSamples); @@ -232,3 +249,31 @@ void MainWindow::onNumOfSamplesChanged(i } } } + +void MainWindow::onAutoScaleChecked(bool checked) +{ + if (checked) + { + ui->plot->setAxisAutoScale(QwtPlot::yLeft); + ui->lYmin->setEnabled(false); + ui->lYmax->setEnabled(false); + ui->spYmin->setEnabled(false); + ui->spYmax->setEnabled(false); + } + else + { + ui->lYmin->setEnabled(true); + ui->lYmax->setEnabled(true); + ui->spYmin->setEnabled(true); + ui->spYmax->setEnabled(true); + + ui->plot->setAxisScale(QwtPlot::yLeft, ui->spYmin->value(), + ui->spYmax->value()); + } +} + +void MainWindow::onYScaleChanged() +{ + ui->plot->setAxisScale(QwtPlot::yLeft, ui->spYmin->value(), + ui->spYmax->value()); +} diff --git a/mainwindow.h b/mainwindow.h --- a/mainwindow.h +++ b/mainwindow.h @@ -41,6 +41,8 @@ private slots: void onPortError(QSerialPort::SerialPortError error); void onNumOfSamplesChanged(int value); + void onAutoScaleChecked(bool checked); + void onYScaleChanged(); signals: void portToggled(bool open); diff --git a/mainwindow.ui b/mainwindow.ui --- a/mainwindow.ui +++ b/mainwindow.ui @@ -440,13 +440,19 @@ QFormLayout::AllNonFixedFieldsGrow - - - - + + + false + + + + 75 + 16777215 + + - 1.000000000000000 + 0.000000000000000 @@ -474,19 +480,48 @@ - + + + Auto Scale Y Axis + + + true + + + + + + + false + Ymin - + + + false + Ymax + + + + false + + + + 75 + 16777215 + + + + @@ -501,7 +536,7 @@ 0 0 653 - 20 + 23