Updating zoom and axis across plots for consistent zoom levels and behavior.
authorTom Rondeau <trondeau@vt.edu>
Sun, 9 May 2010 17:06:20 +0000 (13:06 -0400)
committerTom Rondeau <trondeau@vt.edu>
Sun, 9 May 2010 17:06:20 +0000 (13:06 -0400)
gr-qtgui/src/lib/ConstellationDisplayPlot.cc
gr-qtgui/src/lib/FrequencyDisplayPlot.cc
gr-qtgui/src/lib/TimeDomainDisplayPlot.cc
gr-qtgui/src/lib/WaterfallDisplayPlot.cc

index 9d2cb385d073ae5f416fe54b51facc06bdd1bf05..e8e6288f5bf7c6924296e1473ba59ccd624a4c2c 100644 (file)
@@ -56,12 +56,10 @@ ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent)
   canvas()->setPalette(palette);  
 
   setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine);
-  //setAxisScale(QwtPlot::xBottom, -1.0, 1.0);
   set_xaxis(-2.0, 2.0);
   setAxisTitle(QwtPlot::xBottom, "In-phase");
 
   setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine);
-  //setAxisScale(QwtPlot::yLeft, -1.0, 1.0);
   set_yaxis(-2.0, 2.0);
   setAxisTitle(QwtPlot::yLeft, "Quadrature");
 
index af705fb9657058331347e2d0c187fcedaa6b08ba..f2cde322efd1569f2ccaf8d1a5c46bee6fdebb5a 100644 (file)
@@ -120,9 +120,8 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent)
   palette.setColor(canvas()->backgroundRole(), QColor("white"));
   canvas()->setPalette(palette);  
 
-  setAxisScaleDraw(QwtPlot::xBottom, new FreqDisplayScaleDraw(0));
-  setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency);
   setAxisTitle(QwtPlot::xBottom, "Frequency (Hz)");
+  setAxisScaleDraw(QwtPlot::xBottom, new FreqDisplayScaleDraw(0));
 
   _minYAxis = -120;
   _maxYAxis = 10;
@@ -166,9 +165,6 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent)
     _maxFFTPoints[number] = -280.0;
   }
 
-  _resetXAxisPoints();
-
-
   // set up peak marker
   QwtSymbol symbol;
 
@@ -218,6 +214,9 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent)
   const QColor c(Qt::darkRed);
   _zoomer->setRubberBandPen(c);
   _zoomer->setTrackerPen(c);
+
+  // Do this after the zoomer has been built
+  _resetXAxisPoints();
 }
 
 FrequencyDisplayPlot::~FrequencyDisplayPlot()
@@ -263,22 +262,26 @@ FrequencyDisplayPlot::SetFrequencyRange(const double constStartFreq,
     stopFreq = (stopFreq + centerFreq);
   }
 
-  _startFrequency = startFreq;
-  _stopFrequency = stopFreq;
-  _resetXAxisPoints();
+  bool reset = false;
+  if((startFreq != _startFrequency) || (stopFreq != _stopFrequency))
+    reset = true;
 
-  double display_units = ceil(log10(units)/2.0);
-  setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency);
-  setAxisScaleDraw(QwtPlot::xBottom, new FreqDisplayScaleDraw(display_units));
-  setAxisTitle(QwtPlot::xBottom, QString("Frequency (%1)").arg(strunits.c_str()));
-  ((FreqDisplayZoomer*)_zoomer)->SetFrequencyPrecision(display_units);
-  ((FreqDisplayZoomer*)_zoomer)->SetUnitType(strunits);
+  if(stopFreq > startFreq) {
+    _startFrequency = startFreq;
+    _stopFrequency = stopFreq;
+    
+    if((axisScaleDraw(QwtPlot::xBottom) != NULL) && (_zoomer != NULL)){
+      double display_units = ceil(log10(units)/2.0);
+      setAxisScaleDraw(QwtPlot::xBottom, new FreqDisplayScaleDraw(display_units));
+      setAxisTitle(QwtPlot::xBottom, QString("Frequency (%1)").arg(strunits.c_str()));
 
-  // Load up the new base zoom settings
-  _zoomer->setZoomBase();
-  
-  // Zooms back to the base and clears any other zoom levels
-  _zoomer->zoom(0);
+      if(reset)
+       _resetXAxisPoints();
+      
+      ((FreqDisplayZoomer*)_zoomer)->SetFrequencyPrecision(display_units);
+      ((FreqDisplayZoomer*)_zoomer)->SetUnitType(strunits);
+    }
+  }
 }
 
 
@@ -406,6 +409,17 @@ FrequencyDisplayPlot::_resetXAxisPoints()
     _xAxisPoints[loc] = freqValue;
     freqValue += fft_bin_size;
   }
+
+  setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency);
+
+  // Set up zoomer base for maximum unzoom x-axis
+  // and reset to maximum unzoom level
+  QwtDoubleRect zbase = _zoomer->zoomBase();
+  zbase.setLeft(_startFrequency);
+  zbase.setRight(_stopFrequency);
+  _zoomer->zoom(zbase);
+  _zoomer->setZoomBase(zbase);
+  _zoomer->zoom(0);
 }
 
 void
index e6f6581d230694233f2aa2d7fabbb48795b0e0a1..c299f83a4a09ea56f6b39df9d039cbfc1c96c794 100644 (file)
@@ -237,6 +237,15 @@ void TimeDomainDisplayPlot::_resetXAxisPoints()
     _xAxisPoints[loc] = loc*delt;
   }
   setAxisScale(QwtPlot::xBottom, 0, _numPoints*delt);
+
+  // Set up zoomer base for maximum unzoom x-axis
+  // and reset to maximum unzoom level
+  QwtDoubleRect zbase = _zoomer->zoomBase();
+  zbase.setLeft(0);
+  zbase.setRight(_numPoints*delt);
+  _zoomer->zoom(zbase);
+  _zoomer->setZoomBase(zbase);
+  _zoomer->zoom(0);
 }
 
 void TimeDomainDisplayPlot::LegendEntryChecked(QwtPlotItem* plotItem, bool on)
@@ -248,16 +257,19 @@ void
 TimeDomainDisplayPlot::SetSampleRate(double sr, double units,
                                     const std::string &strunits)
 {
-  _sampleRate = sr/units;
-  _resetXAxisPoints();
-
-  // While we could change the displayed sigfigs based on the unit being
-  // displayed, I think it looks better by just setting it to 4 regardless.
-  //double display_units = ceil(log10(units)/2.0);
-  double display_units = 4;
-  setAxisTitle(QwtPlot::xBottom, QString("Time (%1)").arg(strunits.c_str()));
-  ((TimeDomainDisplayZoomer*)_zoomer)->SetTimePrecision(display_units);
-  ((TimeDomainDisplayZoomer*)_zoomer)->SetUnitType(strunits);
+  double newsr = sr/units;
+  if(newsr != _sampleRate) {
+    _sampleRate = sr/units;
+    _resetXAxisPoints();
+    
+    // While we could change the displayed sigfigs based on the unit being
+    // displayed, I think it looks better by just setting it to 4 regardless.
+    //double display_units = ceil(log10(units)/2.0);
+    double display_units = 4;
+    setAxisTitle(QwtPlot::xBottom, QString("Time (%1)").arg(strunits.c_str()));
+    ((TimeDomainDisplayZoomer*)_zoomer)->SetTimePrecision(display_units);
+    ((TimeDomainDisplayZoomer*)_zoomer)->SetUnitType(strunits);
+  }
 }
 
 #endif /* TIME_DOMAIN_DISPLAY_PLOT_C */
index 298eaffe94e36f2e8b374756622319efd3ba7bf5..e0804fa64083bcbd379d81c1fa3fa8892d11a849 100644 (file)
@@ -298,6 +298,8 @@ WaterfallDisplayPlot::Reset()
   _waterfallData->ResizeData(_startFrequency, _stopFrequency, _numPoints);
   _waterfallData->Reset();
 
+  setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency);
+
   // Load up the new base zoom settings
   QwtDoubleRect newSize = _zoomer->zoomBase();
   newSize.setLeft(_startFrequency);
@@ -332,12 +334,11 @@ WaterfallDisplayPlot::SetFrequencyRange(const double constStartFreq,
   if(stopFreq > startFreq) {
     _startFrequency = startFreq;
     _stopFrequency = stopFreq;
-
  
     if((axisScaleDraw(QwtPlot::xBottom) != NULL) && (_zoomer != NULL)){
       double display_units = ceil(log10(units)/2.0);
-      setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency);
       setAxisScaleDraw(QwtPlot::xBottom, new WaterfallFreqDisplayScaleDraw(display_units));
+      setAxisTitle(QwtPlot::xBottom, QString("Frequency (%1)").arg(strunits.c_str()));
 
       if(reset) {
        Reset();
@@ -345,12 +346,6 @@ WaterfallDisplayPlot::SetFrequencyRange(const double constStartFreq,
 
       ((WaterfallZoomer*)_zoomer)->SetFrequencyPrecision(display_units);
       ((WaterfallZoomer*)_zoomer)->SetUnitType(strunits);
-
-      // Load up the new base zoom settings
-      _zoomer->setZoomBase();
-      
-      // Zooms back to the base and clears any other zoom levels
-      _zoomer->zoom(0);
     }
   }
 }