diff options
author | Tom Rondeau <tom@trondeau.com> | 2014-07-11 15:56:45 -0400 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2014-07-11 15:56:45 -0400 |
commit | ded480efed91be8fa80938c0ea5474990e2f7302 (patch) | |
tree | e0ca716a9e30f04b743a1f0ef683dd1e324cc7b6 /gr-qtgui/lib/TimeDomainDisplayPlot.cc | |
parent | d6330a5842081c77761b832fa273f6325ee11316 (diff) |
qtgui: allows users to set title and unit of Y axis for qt time plotter.
Diffstat (limited to 'gr-qtgui/lib/TimeDomainDisplayPlot.cc')
-rw-r--r-- | gr-qtgui/lib/TimeDomainDisplayPlot.cc | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index 8c0601a5b5..3fc592481f 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -66,7 +66,7 @@ public: #else /* QWT_VERSION < 0x060100 */ TimeDomainDisplayZoomer(QWidget* canvas, const unsigned int timePrecision) #endif /* QWT_VERSION < 0x060100 */ - : QwtPlotZoomer(canvas),TimePrecisionClass(timePrecision) + : QwtPlotZoomer(canvas),TimePrecisionClass(timePrecision),d_yUnitType("V") { setTrackerMode(QwtPicker::AlwaysOn); } @@ -85,23 +85,30 @@ public: d_unitType = type; } + void setYUnitType(const std::string &type) + { + d_yUnitType = type; + } + protected: using QwtPlotZoomer::trackerText; virtual QwtText trackerText( const QPoint& p ) const { QwtText t; QwtDoublePoint dp = QwtPlotZoomer::invTransform(p); - if((dp.y() > 0.0001) && (dp.y() < 10000)) { - t.setText(QString("%1 %2, %3 V"). + if((fabs(dp.y()) > 0.0001) && (fabs(dp.y()) < 10000)) { + t.setText(QString("%1 %2, %3 %4"). arg(dp.x(), 0, 'f', getTimePrecision()). arg(d_unitType.c_str()). - arg(dp.y(), 0, 'f', 4)); + arg(dp.y(), 0, 'f', 4). + arg(d_yUnitType.c_str())); } else { - t.setText(QString("%1 %2, %3 V"). + t.setText(QString("%1 %2, %3 %4"). arg(dp.x(), 0, 'f', getTimePrecision()). arg(d_unitType.c_str()). - arg(dp.y(), 0, 'e', 4)); + arg(dp.y(), 0, 'e', 4). + arg(d_yUnitType.c_str())); } return t; @@ -109,6 +116,7 @@ protected: private: std::string d_unitType; + std::string d_yUnitType; }; @@ -550,4 +558,15 @@ TimeDomainDisplayPlot::enableTagMarker(int which, bool en) throw std::runtime_error("TimeDomainDisplayPlot: enabled tag marker does not exist.\n"); } +void +TimeDomainDisplayPlot::setYLabel(const std::string &label, + const std::string &unit) +{ + std::string l = label; + if(unit.length() > 0) + l += " (" + unit + ")"; + setAxisTitle(QwtPlot::yLeft, QString(l.c_str())); + ((TimeDomainDisplayZoomer*)d_zoomer)->setYUnitType(unit); +} + #endif /* TIME_DOMAIN_DISPLAY_PLOT_C */ |