Changeset - bfd45d598368
[Not reviewed]
Hasan Yavuz ÖZDERYA - 9 years ago 2017-03-13 02:23:08
hy@ozderya.net
added ui elements for x axis scaling
8 files changed with 189 insertions and 73 deletions:
0 comments (0 inline, 0 general)
src/framebufferseries.cpp
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
@@ -21,9 +21,19 @@
 

	
 
FrameBufferSeries::FrameBufferSeries(FrameBuffer* buffer)
 
{
 
    xAsIndex = true;
 
    _xmin = 0;
 
    _xmax = 1;
 
    _buffer = buffer;
 
}
 

	
 
void FrameBufferSeries::setXAxis(bool asIndex, double xmin, double xmax)
 
{
 
    xAsIndex = asIndex;
 
    _xmin = xmin;
 
    _xmax = xmax;
 
}
 

	
 
size_t FrameBufferSeries::size() const
 
{
 
    return _buffer->size();
 
@@ -31,7 +41,14 @@ size_t FrameBufferSeries::size() const
 

	
 
QPointF FrameBufferSeries::sample(size_t i) const
 
{
 
    return QPointF(i, _buffer->sample(i));
 
    if (xAsIndex)
 
    {
 
        return QPointF(i, _buffer->sample(i));
 
    }
 
    else
 
    {
 
        return QPointF(i * (_xmax - _xmin) / size() + _xmin, _buffer->sample(i));
 
    }
 
}
 

	
 
QRectF FrameBufferSeries::boundingRect() const
src/framebufferseries.h
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
@@ -37,6 +37,9 @@ class FrameBufferSeries : public QwtSeri
 
public:
 
    FrameBufferSeries(FrameBuffer* buffer);
 

	
 
    /// Behavior of X axis
 
    void setXAxis(bool asIndex, double xmin, double xmax);
 

	
 
    // QwtSeriesData implementations
 
    size_t size() const;
 
    QPointF sample(size_t i) const;
 
@@ -44,6 +47,9 @@ public:
 

	
 
private:
 
    FrameBuffer* _buffer;
 
    bool xAsIndex;
 
    double _xmin;
 
    double _xmax;
 
};
 

	
 
#endif // FRAMEBUFFERSERIES_H
src/mainwindow.cpp
Show inline comments
 
@@ -139,7 +139,7 @@ MainWindow::MainWindow(QWidget *parent) 
 
    connect(&plotControlPanel, &PlotControlPanel::numOfSamplesChanged,
 
            plotMan, &PlotManager::onNumOfSamplesChanged);
 

	
 
    connect(&plotControlPanel, &PlotControlPanel::scaleChanged,
 
    connect(&plotControlPanel, &PlotControlPanel::yScaleChanged,
 
            plotMan, &PlotManager::setAxis);
 

	
 
    QObject::connect(ui->actionClear, SIGNAL(triggered(bool)),
src/plotcontrolpanel.cpp
Show inline comments
 
@@ -181,7 +181,7 @@ void PlotControlPanel::onAutoScaleChecke
 
        ui->spYmin->setEnabled(false);
 
        ui->spYmax->setEnabled(false);
 

	
 
        emit scaleChanged(true); // autoscale
 
        emit yScaleChanged(true); // autoscale
 
    }
 
    else
 
    {
 
@@ -190,13 +190,13 @@ void PlotControlPanel::onAutoScaleChecke
 
        ui->spYmin->setEnabled(true);
 
        ui->spYmax->setEnabled(true);
 

	
 
        emit scaleChanged(false, ui->spYmin->value(), ui->spYmax->value());
 
        emit yScaleChanged(false, ui->spYmin->value(), ui->spYmax->value());
 
    }
 
}
 

	
 
void PlotControlPanel::onYScaleChanged()
 
{
 
    emit scaleChanged(false, ui->spYmin->value(), ui->spYmax->value());
 
    emit yScaleChanged(false, ui->spYmin->value(), ui->spYmax->value());
 
}
 

	
 
bool PlotControlPanel::autoScale()
src/plotcontrolpanel.h
Show inline comments
 
@@ -53,7 +53,7 @@ public:
 

	
 
signals:
 
    void numOfSamplesChanged(int value);
 
    void scaleChanged(bool autoScaled, double yMin = 0, double yMax = 1);
 
    void yScaleChanged(bool autoScaled, double yMin = 0, double yMax = 1);
 

	
 
private:
 
    Ui::PlotControlPanel *ui;
src/plotcontrolpanel.ui
Show inline comments
 
@@ -6,7 +6,7 @@
 
   <rect>
 
    <x>0</x>
 
    <y>0</y>
 
    <width>590</width>
 
    <width>706</width>
 
    <height>187</height>
 
   </rect>
 
  </property>
 
@@ -157,6 +157,87 @@
 
      </widget>
 
     </item>
 
     <item row="1" column="0">
 
      <widget class="QCheckBox" name="cbIndex">
 
       <property name="text">
 
        <string>Index as X AXis</string>
 
       </property>
 
       <property name="checked">
 
        <bool>true</bool>
 
       </property>
 
      </widget>
 
     </item>
 
     <item row="1" column="1">
 
      <layout class="QHBoxLayout" name="horizontalLayout_4">
 
       <item>
 
        <widget class="QLabel" name="lXmin">
 
         <property name="enabled">
 
          <bool>false</bool>
 
         </property>
 
         <property name="text">
 
          <string>Xmin</string>
 
         </property>
 
        </widget>
 
       </item>
 
       <item>
 
        <widget class="QDoubleSpinBox" name="spXmin">
 
         <property name="enabled">
 
          <bool>false</bool>
 
         </property>
 
         <property name="minimumSize">
 
          <size>
 
           <width>75</width>
 
           <height>0</height>
 
          </size>
 
         </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>
 
        <widget class="QLabel" name="lXmax">
 
         <property name="enabled">
 
          <bool>false</bool>
 
         </property>
 
         <property name="text">
 
          <string>Xmax</string>
 
         </property>
 
        </widget>
 
       </item>
 
       <item>
 
        <widget class="QDoubleSpinBox" name="spXmax">
 
         <property name="enabled">
 
          <bool>false</bool>
 
         </property>
 
         <property name="maximumSize">
 
          <size>
 
           <width>75</width>
 
           <height>16777215</height>
 
          </size>
 
         </property>
 
         <property name="toolTip">
 
          <string>upper limit of Y axis</string>
 
         </property>
 
         <property name="maximum">
 
          <double>1000.000000000000000</double>
 
         </property>
 
         <property name="value">
 
          <double>1000.000000000000000</double>
 
         </property>
 
        </widget>
 
       </item>
 
      </layout>
 
     </item>
 
     <item row="2" column="0">
 
      <widget class="QCheckBox" name="cbAutoScale">
 
       <property name="text">
 
        <string>Auto Scale Y Axis</string>
 
@@ -166,75 +247,85 @@
 
       </property>
 
      </widget>
 
     </item>
 
     <item row="2" column="0">
 
      <widget class="QLabel" name="lYmax">
 
       <property name="enabled">
 
        <bool>false</bool>
 
       </property>
 
       <property name="text">
 
        <string>Ymax</string>
 
       </property>
 
      </widget>
 
     <item row="2" column="1">
 
      <layout class="QHBoxLayout" name="horizontalLayout_3">
 
       <item>
 
        <widget class="QLabel" name="lYmin">
 
         <property name="enabled">
 
          <bool>false</bool>
 
         </property>
 
         <property name="text">
 
          <string>Ymin</string>
 
         </property>
 
        </widget>
 
       </item>
 
       <item>
 
        <widget class="QDoubleSpinBox" name="spYmin">
 
         <property name="enabled">
 
          <bool>false</bool>
 
         </property>
 
         <property name="minimumSize">
 
          <size>
 
           <width>75</width>
 
           <height>0</height>
 
          </size>
 
         </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>
 
        <widget class="QLabel" name="lYmax">
 
         <property name="enabled">
 
          <bool>false</bool>
 
         </property>
 
         <property name="text">
 
          <string>Ymax</string>
 
         </property>
 
        </widget>
 
       </item>
 
       <item>
 
        <widget class="QDoubleSpinBox" name="spYmax">
 
         <property name="enabled">
 
          <bool>false</bool>
 
         </property>
 
         <property name="maximumSize">
 
          <size>
 
           <width>75</width>
 
           <height>16777215</height>
 
          </size>
 
         </property>
 
         <property name="toolTip">
 
          <string>upper limit of Y axis</string>
 
         </property>
 
         <property name="maximum">
 
          <double>1000.000000000000000</double>
 
         </property>
 
         <property name="value">
 
          <double>1000.000000000000000</double>
 
         </property>
 
        </widget>
 
       </item>
 
      </layout>
 
     </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>
 
       <property name="toolTip">
 
        <string>upper limit of Y axis</string>
 
       </property>
 
       <property name="maximum">
 
        <double>1000.000000000000000</double>
 
       </property>
 
       <property name="value">
 
        <double>1000.000000000000000</double>
 
       </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="0">
 
     <item row="5" column="0">
 
      <widget class="QLabel" name="label">
 
       <property name="text">
 
        <string>Select Range Preset:</string>
 
       </property>
 
      </widget>
 
     </item>
 
     <item row="4" column="1">
 
     <item row="5" column="1">
 
      <widget class="QComboBox" name="cbRangePresets"/>
 
     </item>
 
    </layout>
src/plotmanager.cpp
Show inline comments
 
@@ -259,7 +259,9 @@ Plot* PlotManager::addPlotWidget()
 
void PlotManager::addCurve(QString title, FrameBuffer* buffer)
 
{
 
    auto curve = new QwtPlotCurve(title);
 
    curve->setSamples(new FrameBufferSeries(buffer));
 
    auto series = new FrameBufferSeries(buffer);
 
    series->setXAxis(false, 100, 500);
 
    curve->setSamples(series);
 
    _addCurve(curve);
 
}
 

	
src/plotmanager.h
Show inline comments
 
@@ -65,7 +65,7 @@ public slots:
 
    /// Enable display of a "DEMO" label on each plot
 
    void showDemoIndicator(bool show = true);
 
    /// Set the Y axis
 
    void setAxis(bool autoScaled, double yMin = 0, double yMax = 1);
 
    void setYAxis(bool autoScaled, double yMin = 0, double yMax = 1);
 
    /// Display an animation for snapshot
 
    void flashSnapshotOverlay();
 
    /// Should be called to update zoom base
0 comments (0 inline, 0 general)