Fixing constellation zoomer's label.
[debian/gnuradio] / gr-qtgui / src / lib / FrequencyDisplayPlot.cc
index 154c8d2341a62fea73fae9e9ed6f7fc87e076b07..af705fb9657058331347e2d0c187fcedaa6b08ba 100644 (file)
@@ -73,13 +73,22 @@ public:
     updateDisplay();
   }
 
+  void SetUnitType(const std::string &type)
+  {
+    _unitType = type;
+  }
+
 protected:
   virtual QwtText trackerText( const QwtDoublePoint& p ) const 
   {
-    QwtText t(QString("%1 %2, %3 dB").arg(p.x(), 0, 'f', GetFrequencyPrecision()).arg( (GetFrequencyPrecision() == 0) ? "Hz" : "kHz").arg(p.y(), 0, 'f', 2));
-
+    QwtText t(QString("%1 %2, %3 dB").
+             arg(p.x(), 0, 'f', GetFrequencyPrecision()).
+             arg(_unitType.c_str()).arg(p.y(), 0, 'f', 2));
     return t;
   }
+
+private:
+  std::string _unitType;
 };
 
 FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent)
@@ -91,9 +100,7 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent)
   timespec_reset(&_lastReplot);
 
   resize(parent->width(), parent->height());
-
-  _displayIntervalTime = (1.0/10.0); // 1/10 of a second between updates
-
+  
   _useCenterFrequencyFlag = false;
 
   _numPoints = 1024;
@@ -148,7 +155,7 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent)
 
   _upper_intensity_marker = new QwtPlotMarker();
   _upper_intensity_marker->setLineStyle(QwtPlotMarker::HLine);
-  _upper_intensity_marker->setLinePen(QPen(Qt::green));
+  _upper_intensity_marker->setLinePen(QPen(Qt::green, 0, Qt::DotLine));
   _upper_intensity_marker->attach(this);
 
   memset(_dataPoints, 0x0, _numPoints*sizeof(double));
@@ -260,10 +267,12 @@ FrequencyDisplayPlot::SetFrequencyRange(const double constStartFreq,
   _stopFrequency = stopFreq;
   _resetXAxisPoints();
 
+  double display_units = ceil(log10(units)/2.0);
   setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency);
-  setAxisScaleDraw(QwtPlot::xBottom, new FreqDisplayScaleDraw(2));
+  setAxisScaleDraw(QwtPlot::xBottom, new FreqDisplayScaleDraw(display_units));
   setAxisTitle(QwtPlot::xBottom, QString("Frequency (%1)").arg(strunits.c_str()));
-  ((FreqDisplayZoomer*)_zoomer)->SetFrequencyPrecision(2);
+  ((FreqDisplayZoomer*)_zoomer)->SetFrequencyPrecision(display_units);
+  ((FreqDisplayZoomer*)_zoomer)->SetUnitType(strunits);
 
   // Load up the new base zoom settings
   _zoomer->setZoomBase();
@@ -288,8 +297,6 @@ FrequencyDisplayPlot::GetStopFrequency() const
 void
 FrequencyDisplayPlot::replot()
 {
-  const timespec startTime = get_highres_clock();
-
   _markerNoiseFloorAmplitude->setYValue(_noiseFloorAmplitude);
   
   // Make sure to take into account the start frequency
@@ -302,26 +309,26 @@ FrequencyDisplayPlot::replot()
   _markerPeakAmplitude->setYValue(_peakAmplitude);
   
   QwtPlot::replot();
-
-  double differenceTime = (diff_timespec(get_highres_clock(), startTime));
-
-  differenceTime *= 99.0;
-  // Require at least a 10% duty cycle
-  if(differenceTime > (1.0/10.0)){
-    _displayIntervalTime = differenceTime;
-  }
+}
+void
+FrequencyDisplayPlot::resizeSlot( QSize *s )
+{
+  resize(s->width(), s->height());
 }
 
 void
 FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDataPoints,
                                  const double noiseFloorAmplitude, const double peakFrequency,
-                                 const double peakAmplitude)
+                                 const double peakAmplitude, const double timeInterval)
 {
-  if(numDataPoints > 0){
-
-    if(numDataPoints != _numPoints){
+  // Only update plot if there is data and if the time interval has elapsed
+  if((numDataPoints > 0) && 
+     (diff_timespec(get_highres_clock(), _lastReplot) > timeInterval)) {
+    
+    if(numDataPoints != _numPoints) {
       _numPoints = numDataPoints;
-
+      
       delete[] _dataPoints;
       delete[] _minFFTPoints;
       delete[] _maxFFTPoints;
@@ -334,11 +341,12 @@ FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDat
       _fft_plot_curve->setRawData(_xAxisPoints, _dataPoints, _numPoints);
       _min_fft_plot_curve->setRawData(_xAxisPoints, _minFFTPoints, _numPoints);
       _max_fft_plot_curve->setRawData(_xAxisPoints, _maxFFTPoints, _numPoints);
-
+      
       _resetXAxisPoints();
       ClearMaxData();
       ClearMinData();
     }
+    
     memcpy(_dataPoints, dataPoints, numDataPoints*sizeof(double));
     for(int64_t point = 0; point < numDataPoints; point++){
       if(dataPoints[point] < _minFFTPoints[point]){
@@ -353,14 +361,10 @@ FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDat
     _peakFrequency = peakFrequency;
     _peakAmplitude = peakAmplitude;
 
-  }
+    SetUpperIntensityLevel(_peakAmplitude);
 
-  // Allow at least a 50% duty cycle
-  if(diff_timespec(get_highres_clock(), _lastReplot) > _displayIntervalTime){
-    // Only replot the screen if it is visible
-    if(isVisible()){
-      replot();
-    }
+    replot();
+    
     _lastReplot = get_highres_clock();
   }
 }
@@ -369,7 +373,7 @@ void
 FrequencyDisplayPlot::ClearMaxData()
 {
   for(int64_t number = 0; number < _numPoints; number++){
-    _maxFFTPoints[number] = _maxYAxis;
+    _maxFFTPoints[number] = _minYAxis;
   }
 }
 
@@ -377,7 +381,7 @@ void
 FrequencyDisplayPlot::ClearMinData()
 {
   for(int64_t number = 0; number < _numPoints; number++){
-    _minFFTPoints[number] = _minYAxis;
+    _minFFTPoints[number] = _maxYAxis;
   }
 }