Changeset - 90fb38350cfd
[Not reviewed]
default
0 3 0
Hasan Yavuz Ă–ZDERYA - 11 years ago 2015-03-08 17:15:46
hy@ozderya.net
implemented plot axis limit controls
3 files changed with 91 insertions and 9 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -2,7 +2,8 @@
 
#include "ui_mainwindow.h"
 
#include <QSerialPortInfo>
 
#include <QtDebug>
 

	
 
#include <qwt_plot.h>
 
#include <limits.h>
 
#include "utils.h"
 

	
 
MainWindow::MainWindow(QWidget *parent) :
 
@@ -35,6 +36,15 @@ MainWindow::MainWindow(QWidget *parent) 
 
    QObject::connect(ui->spNumOfSamples, SELECT<int>::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<double>::min(),
 
                         std::numeric_limits<double>::max());
 

	
 
    ui->spYmax->setRange(std::numeric_limits<double>::min(),
 
                         std::numeric_limits<double>::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());
 
}
mainwindow.h
Show inline comments
 
@@ -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);
mainwindow.ui
Show inline comments
 
@@ -440,13 +440,19 @@
 
          <property name="fieldGrowthPolicy">
 
           <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
 
          </property>
 
          <item row="2" column="1">
 
           <widget class="QDoubleSpinBox" name="spYmax"/>
 
          </item>
 
          <item row="1" column="1">
 
          <item row="3" column="1">
 
           <widget class="QDoubleSpinBox" name="spYmin">
 
            <property name="enabled">
 
             <bool>false</bool>
 
            </property>
 
            <property name="maximumSize">
 
             <size>
 
              <width>75</width>
 
              <height>16777215</height>
 
             </size>
 
            </property>
 
            <property name="value">
 
             <double>1.000000000000000</double>
 
             <double>0.000000000000000</double>
 
            </property>
 
           </widget>
 
          </item>
 
@@ -474,19 +480,48 @@
 
           </widget>
 
          </item>
 
          <item row="1" column="0">
 
           <widget class="QCheckBox" name="cbYmin">
 
           <widget class="QCheckBox" name="cbAutoScale">
 
            <property name="text">
 
             <string>Auto Scale Y Axis</string>
 
            </property>
 
            <property name="checked">
 
             <bool>true</bool>
 
            </property>
 
           </widget>
 
          </item>
 
          <item row="3" column="0">
 
           <widget class="QLabel" name="lYmin">
 
            <property name="enabled">
 
             <bool>false</bool>
 
            </property>
 
            <property name="text">
 
             <string>Ymin</string>
 
            </property>
 
           </widget>
 
          </item>
 
          <item row="2" column="0">
 
           <widget class="QCheckBox" name="cbYMax">
 
           <widget class="QLabel" name="lYmax">
 
            <property name="enabled">
 
             <bool>false</bool>
 
            </property>
 
            <property name="text">
 
             <string>Ymax</string>
 
            </property>
 
           </widget>
 
          </item>
 
          <item row="2" column="1">
 
           <widget class="QDoubleSpinBox" name="spYmax">
 
            <property name="enabled">
 
             <bool>false</bool>
 
            </property>
 
            <property name="maximumSize">
 
             <size>
 
              <width>75</width>
 
              <height>16777215</height>
 
             </size>
 
            </property>
 
           </widget>
 
          </item>
 
         </layout>
 
        </item>
 
       </layout>
 
@@ -501,7 +536,7 @@
 
     <x>0</x>
 
     <y>0</y>
 
     <width>653</width>
 
     <height>20</height>
 
     <height>23</height>
 
    </rect>
 
   </property>
 
   <widget class="QMenu" name="menuFile">
0 comments (0 inline, 0 general)