Changeset - eb39452a2796
[Not reviewed]
default
0 3 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-09-13 14:12:08
hy@ozderya.net
added scale range presets
3 files changed with 86 insertions and 34 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -40,6 +40,14 @@
 
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
 
#endif
 

	
 
struct Range
 
{
 
    double rmin;
 
    double rmax;
 
};
 

	
 
Q_DECLARE_METATYPE(Range);
 

	
 
MainWindow::MainWindow(QWidget *parent) :
 
    QMainWindow(parent),
 
    ui(new Ui::MainWindow),
 
@@ -156,6 +164,31 @@ MainWindow::MainWindow(QWidget *parent) 
 
    ui->plot->showGrid(ui->actionGrid->isChecked());
 
    ui->plot->showMinorGrid(ui->actionMinorGrid->isChecked());
 

	
 
    // init scale range preset list
 
    for (int nbits = 8; nbits <= 24; nbits++) // signed binary formats
 
    {
 
        int rmax = pow(2, nbits-1)-1;
 
        int rmin = -rmax-1;
 
        Range r = {double(rmin),  double(rmax)};
 
        ui->cbRangePresets->addItem(
 
            QString().sprintf("Signed %d bits %d to +%d", nbits, rmin, rmax),
 
            QVariant::fromValue(r));
 
    }
 
    for (int nbits = 8; nbits <= 24; nbits++) // unsigned binary formats
 
    {
 
        int rmax = pow(2, nbits)-1;
 
        ui->cbRangePresets->addItem(
 
            QString().sprintf("Unsigned %d bits %d to +%d", nbits, 0, rmax),
 
            QVariant::fromValue(Range{0, double(rmax)}));
 
    }
 
    ui->cbRangePresets->addItem("-1 to +1", QVariant::fromValue(Range{-1, +1}));
 
    ui->cbRangePresets->addItem("0 to +1", QVariant::fromValue(Range{0, +1}));
 
    ui->cbRangePresets->addItem("-100 to +100", QVariant::fromValue(Range{-100, +100}));
 
    ui->cbRangePresets->addItem("0 to +100", QVariant::fromValue(Range{0, +100}));
 

	
 
    QObject::connect(ui->cbRangePresets, SIGNAL(activated(int)),
 
                     this, SLOT(onRangeSelected()));
 

	
 
    // init number format
 
    if (numberFormatButtons.checkedId() >= 0)
 
    {
 
@@ -469,6 +502,14 @@ void MainWindow::onYScaleChanged()
 
    ui->plot->setAxis(false,  ui->spYmin->value(), ui->spYmax->value());
 
}
 

	
 
void MainWindow::onRangeSelected()
 
{
 
    Range r = ui->cbRangePresets->currentData().value<Range>();
 
    ui->spYmin->setValue(r.rmin);
 
    ui->spYmax->setValue(r.rmax);
 
    ui->cbAutoScale->setChecked(false);
 
}
 

	
 
void MainWindow::onNumberFormatButtonToggled(int numberFormatId, bool checked)
 
{
 
    if (checked) selectNumberFormat((NumberFormat) numberFormatId);
mainwindow.h
Show inline comments
 
@@ -119,6 +119,7 @@ private slots:
 
    void onNumOfSamplesChanged(int value);
 
    void onAutoScaleChecked(bool checked);
 
    void onYScaleChanged();
 
    void onRangeSelected();
 

	
 
    void onNumOfChannelsChanged(int value);
 
    void onNumberFormatButtonToggled(int numberFormatId, bool checked);
mainwindow.ui
Show inline comments
 
@@ -311,22 +311,10 @@
 
          <property name="fieldGrowthPolicy">
 
           <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
 
          </property>
 
          <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="toolTip">
 
             <string>lower limit of Y axis</string>
 
            </property>
 
            <property name="value">
 
             <double>0.000000000000000</double>
 
          <item row="0" column="0">
 
           <widget class="QLabel" name="label_3">
 
            <property name="text">
 
             <string>Number Of Samples:</string>
 
            </property>
 
           </widget>
 
          </item>
 
@@ -349,13 +337,6 @@
 
            </property>
 
           </widget>
 
          </item>
 
          <item row="0" column="0">
 
           <widget class="QLabel" name="label_3">
 
            <property name="text">
 
             <string>Number Of Samples:</string>
 
            </property>
 
           </widget>
 
          </item>
 
          <item row="1" column="0">
 
           <widget class="QCheckBox" name="cbAutoScale">
 
            <property name="text">
 
@@ -366,16 +347,6 @@
 
            </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="QLabel" name="lYmax">
 
            <property name="enabled">
 
@@ -408,6 +379,45 @@
 
            </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="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="toolTip">
 
             <string>lower limit of Y axis</string>
 
            </property>
 
            <property name="value">
 
             <double>0.000000000000000</double>
 
            </property>
 
           </widget>
 
          </item>
 
          <item row="4" column="1">
 
           <widget class="QComboBox" name="cbRangePresets"/>
 
          </item>
 
          <item row="4" column="0">
 
           <widget class="QLabel" name="label">
 
            <property name="text">
 
             <string>Select Range Preset:</string>
 
            </property>
 
           </widget>
 
          </item>
 
         </layout>
 
        </item>
 
       </layout>
 
@@ -451,7 +461,7 @@
 
     <x>0</x>
 
     <y>0</y>
 
     <width>653</width>
 
     <height>23</height>
 
     <height>27</height>
 
    </rect>
 
   </property>
 
   <widget class="QMenu" name="menuHelp">
0 comments (0 inline, 0 general)