diff options
Diffstat (limited to 'gr-qtgui')
31 files changed, 763 insertions, 166 deletions
diff --git a/gr-qtgui/Makefile.am b/gr-qtgui/Makefile.am index 38033e1ac..e850567cc 100644 --- a/gr-qtgui/Makefile.am +++ b/gr-qtgui/Makefile.am @@ -21,7 +21,7 @@ include $(top_srcdir)/Makefile.common -SUBDIRS = lib +SUBDIRS = include lib doc if PYTHON SUBDIRS += swig python apps grc examples diff --git a/gr-qtgui/doc/.gitignore b/gr-qtgui/doc/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gr-qtgui/doc/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gr-qtgui/doc/Makefile.am b/gr-qtgui/doc/Makefile.am new file mode 100644 index 000000000..b65eb062f --- /dev/null +++ b/gr-qtgui/doc/Makefile.am @@ -0,0 +1,27 @@ +# +# Copyright 2011 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = + +dist_gr_doc_DATA = \ + README.qtgui diff --git a/gr-qtgui/doc/README.qtgui b/gr-qtgui/doc/README.qtgui new file mode 100644 index 000000000..e54c3d907 --- /dev/null +++ b/gr-qtgui/doc/README.qtgui @@ -0,0 +1,12 @@ +This is the gr-qtgui package. It contains various QT-based graphical +user interface blocks that add graphical sinks to a GNU Radio +flowgraph. The Python namespaces is in gnuradio.qtgui, which would be normally +imported as: + + from gnuradio import qtgui + +See the Doxygen documentation for details about the blocks available +in this package. A quick listing of the details can be found in Python +after importing by using: + + help(qtgui) diff --git a/gr-qtgui/doc/qtgui.dox b/gr-qtgui/doc/qtgui.dox new file mode 100644 index 000000000..c7f4b7146 --- /dev/null +++ b/gr-qtgui/doc/qtgui.dox @@ -0,0 +1,77 @@ +/*! \page page_qtgui QT Graphical User Interface + +\section Introduction + +This is the gr-qtgui package. It contains various QT-based graphical +user interface blocks that add graphical sinks to a GNU Radio +flowgraph. The Python namespaces is in gnuradio.qtgui, which would be normally +imported as: + +\code + from gnuradio import qtgui +\endcode + +See the Doxygen documentation for details about the blocks available +in this package. The relevant blocks are listed in the \ref +qtgui_blk group. + +A quick listing of the details can be found in Python after importing +by using: + +\code + help(qtgui) +\endcode + + +\section Dependencies + +The QT GUI blocks require the following dependencies. + +\li QtCore (version >= 4.4) +\li QtGui (version >= 4.4) +\li QtOpenGL (version >= 4.4) +\li PyQt4 for Qt4 (version >= 4.4) +\li Qwt (version >= 5.2) +\li PyQwt5 for Qt4 (version >= 5.2) + +\section Usage + +To use the qtgui interface, a bit of boiler-plate lines must be +included. First, the sink is defined, then it must be exposed from C++ +into Python using the "sip.wrapinstance" command, and finally, the +"show" method is run on the new Python object. This sets up the QT +environment to show the widget, but the qApplication must also be +launched. + +In the "main" function of the code, the qApp is retrieved. Then, after +the GNU Radio top block is started (remember that start() is a +non-blocking call to launch the main thread of the flowgraph), the +qapp's "exec_()" function is called. This function is a blocking call +while the GUI is alive. + +\code +from PyQt4 import Qt +from gnuradio.qtgui import qtgui +import sys, sip + +class grclass(gr.top_block): + .... + + self.snk = qtgui.sink_c(1024, #fftsize + samp_rate, #bw + "QT GUI Plot") #name + + self.snk_win = sip.wrapinstance(self.snk.pyqwidget(), Qt.QWidget) + self.snk_win.show() + +def main(): + qapp = Qt.QApplication(sys.argv) + tb = grclass() + tb.start() + qapp.exec_() + tb.stop() + + +\endcode + +*/ diff --git a/gr-qtgui/include/.gitignore b/gr-qtgui/include/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gr-qtgui/include/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gr-qtgui/include/Makefile.am b/gr-qtgui/include/Makefile.am new file mode 100644 index 000000000..59a030854 --- /dev/null +++ b/gr-qtgui/include/Makefile.am @@ -0,0 +1,33 @@ +# +# Copyright 2011 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +include $(top_srcdir)/Makefile.common + +# These headers get installed in ${prefix}/include/gnuradio +grinclude_HEADERS = \ + gr_qtgui_api.h \ + qtgui_time_sink_c.h \ + qtgui_time_sink_f.h \ + qtgui_sink_c.h \ + qtgui_sink_f.h \ + qtgui_util.h + +libgnuradio_digital_la_LDFLAGS = $(NO_UNDEFINED) $(LTVERSIONFLAGS) diff --git a/gr-qtgui/lib/gr_qtgui_api.h b/gr-qtgui/include/gr_qtgui_api.h index 65033a093..65033a093 100644 --- a/gr-qtgui/lib/gr_qtgui_api.h +++ b/gr-qtgui/include/gr_qtgui_api.h diff --git a/gr-qtgui/lib/qtgui_sink_c.h b/gr-qtgui/include/qtgui_sink_c.h index b0946885c..b04706b14 100644 --- a/gr-qtgui/lib/qtgui_sink_c.h +++ b/gr-qtgui/include/qtgui_sink_c.h @@ -41,6 +41,17 @@ GR_QTGUI_API qtgui_sink_c_sptr qtgui_make_sink_c (int fftsize, int wintype, bool plottime=true, bool plotconst=true, QWidget *parent=NULL); +/*! + * \brief A graphical sink to display freq, spec, time, and const plots. + * \ingroup qtgui_blk + * + * This is a QT-based graphical sink the takes a complex stream and + * plots it. The default action is to plot the signal as a PSD (FFT), + * spectrogram (waterfall), time domain I&Q, and constellation (I + * vs. Q) plots. The plots may be turned off by setting the + * appropriate boolean value in the constructor to False. + */ + class GR_QTGUI_API qtgui_sink_c : public gr_block { private: diff --git a/gr-qtgui/lib/qtgui_sink_f.h b/gr-qtgui/include/qtgui_sink_f.h index 30db05eea..2d79b5eef 100644 --- a/gr-qtgui/lib/qtgui_sink_f.h +++ b/gr-qtgui/include/qtgui_sink_f.h @@ -29,7 +29,6 @@ #include <gr_firdes.h> #include <gri_fft.h> #include <qapplication.h> -//#include <qtgui.h> #include "SpectrumGUIClass.h" class qtgui_sink_f; @@ -39,9 +38,20 @@ GR_QTGUI_API qtgui_sink_f_sptr qtgui_make_sink_f (int fftsize, int wintype, double fc=0, double bw=1.0, const std::string &name="Spectrum Display", bool plotfreq=true, bool plotwaterfall=true, - bool plottime=true, bool plotconst=true, + bool plottime=true, bool plotconst=false, QWidget *parent=NULL); +/*! + * \brief A graphical sink to display freq, spec, and time. + * \ingroup qtgui_blk + * + * This is a QT-based graphical sink the takes a float stream and + * plots it. The default action is to plot the signal as a PSD (FFT), + * spectrogram (waterfall), and time domain plots. The plots may be + * turned off by setting the appropriate boolean value in the + * constructor to False. + */ + class GR_QTGUI_API qtgui_sink_f : public gr_block { private: diff --git a/gr-qtgui/lib/qtgui_time_sink_c.h b/gr-qtgui/include/qtgui_time_sink_c.h index 51d5ad183..ec7cc490b 100644 --- a/gr-qtgui/lib/qtgui_time_sink_c.h +++ b/gr-qtgui/include/qtgui_time_sink_c.h @@ -39,6 +39,17 @@ GR_QTGUI_API qtgui_time_sink_c_sptr qtgui_make_time_sink_c(int size, double bw, int nconnectons=1, QWidget *parent=NULL); +/*! + * \brief A graphical sink to display multiple signals in time. + * \ingroup qtgui_blk + * + * This is a QT-based graphical sink the takes set of a complex + * streams and plots them in the time domain. For each signal, both + * the signal's I and Q parts are plotted, and they are all plotted + * with a different color, and the \a set_title and \a set_color + * functions can be used to change the lable and color for a given + * input number. + */ class GR_QTGUI_API qtgui_time_sink_c : public gr_sync_block { private: diff --git a/gr-qtgui/lib/qtgui_time_sink_f.h b/gr-qtgui/include/qtgui_time_sink_f.h index a69d32877..ff17f8a1b 100644 --- a/gr-qtgui/lib/qtgui_time_sink_f.h +++ b/gr-qtgui/include/qtgui_time_sink_f.h @@ -39,6 +39,15 @@ GR_QTGUI_API qtgui_time_sink_f_sptr qtgui_make_time_sink_f(int size, double bw, int nconnectons=1, QWidget *parent=NULL); +/*! + * \brief A graphical sink to display multiple signals in time. + * \ingroup qtgui_blk + * + * This is a QT-based graphical sink the takes set of a float streams + * and plots them in the time domain. Each signal is plotted with a + * different color, and the \a set_title and \a set_color functions + * can be used to change the lable and color for a given input number. + */ class GR_QTGUI_API qtgui_time_sink_f : public gr_sync_block { private: diff --git a/gr-qtgui/lib/qtgui_util.h b/gr-qtgui/include/qtgui_util.h index 5b129c7b5..7b3692e75 100644 --- a/gr-qtgui/lib/qtgui_util.h +++ b/gr-qtgui/include/qtgui_util.h @@ -44,7 +44,14 @@ public: QwtPickerDblClickPointMachine(); ~QwtPickerDblClickPointMachine(); - virtual CommandList transition( const QwtEventPattern &eventPattern, const QEvent *e); +#if QWT_VERSION < 0x060000 + virtual CommandList transition( const QwtEventPattern &eventPattern, + const QEvent *e); +#else + virtual QList<QwtPickerMachine::Command> + transition( const QwtEventPattern &eventPattern, + const QEvent *e); +#endif }; #endif /* INCLUDED_QTGUI_UTIL_H */ diff --git a/gr-qtgui/lib/ConstellationDisplayPlot.cc b/gr-qtgui/lib/ConstellationDisplayPlot.cc index dda7cfea2..ca7eede36 100644 --- a/gr-qtgui/lib/ConstellationDisplayPlot.cc +++ b/gr-qtgui/lib/ConstellationDisplayPlot.cc @@ -68,11 +68,17 @@ ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent) _imagDataPoints = new double[_numPoints]; // Disable polygon clipping +#if QWT_VERSION < 0x060000 QwtPainter::setDeviceClipping(false); +#else + QwtPainter::setPolylineSplitting(false); +#endif +#if QWT_VERSION < 0x060000 // We don't need the cache here canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false); +#endif QPalette palette; palette.setColor(canvas()->backgroundRole(), QColor("white")); @@ -91,13 +97,22 @@ ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent) _plot_curve->attach(this); _plot_curve->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); _plot_curve->setStyle(QwtPlotCurve::Dots); + +#if QWT_VERSION < 0x060000 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints); +#else + _plot_curve->setRawSamples(_realDataPoints, _imagDataPoints, _numPoints); +#endif memset(_realDataPoints, 0x0, _numPoints*sizeof(double)); memset(_imagDataPoints, 0x0, _numPoints*sizeof(double)); _zoomer = new ConstellationDisplayZoomer(canvas()); + +#if QWT_VERSION < 0x060000 _zoomer->setSelectionFlags(QwtPicker::RectSelection | QwtPicker::DragSelection); +#endif + _zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier); _zoomer->setMousePattern(QwtEventPattern::MouseSelect3, @@ -120,8 +135,14 @@ ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent) // emit the position of clicks on widget _picker = new QwtDblClickPlotPicker(canvas()); + +#if QWT_VERSION < 0x060000 connect(_picker, SIGNAL(selected(const QwtDoublePoint &)), - this, SLOT(OnPickerPointSelected(const QwtDoublePoint &))); + this, SLOT(OnPickerPointSelected(const QwtDoublePoint &))); +#else + connect(_picker, SIGNAL(selected(const QPointF &)), + this, SLOT(OnPickerPointSelected(const QPointF &))); +#endif connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool ) ), this, SLOT(LegendEntryChecked(QwtPlotItem *, bool ) )); @@ -193,12 +214,18 @@ void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints, _realDataPoints = new double[_numPoints]; _imagDataPoints = new double[_numPoints]; +#if QWT_VERSION < 0x060000 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints); +#else + _plot_curve->setRawSamples(_realDataPoints, _imagDataPoints, _numPoints); +#endif } memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double)); memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double)); + replot(); + _lastReplot = gruel::high_res_timer_now(); } } @@ -209,6 +236,7 @@ ConstellationDisplayPlot::LegendEntryChecked(QwtPlotItem* plotItem, bool on) plotItem->setVisible(!on); } +#if QWT_VERSION < 0x060000 void ConstellationDisplayPlot::OnPickerPointSelected(const QwtDoublePoint & p) { @@ -216,5 +244,14 @@ ConstellationDisplayPlot::OnPickerPointSelected(const QwtDoublePoint & p) //fprintf(stderr,"OnPickerPointSelected %f %f\n", point.x(), point.y()); emit plotPointSelected(point); } +#else +void +ConstellationDisplayPlot::OnPickerPointSelected(const QPointF & p) +{ + QPointF point = p; + //fprintf(stderr,"OnPickerPointSelected %f %f\n", point.x(), point.y()); + emit plotPointSelected(point); +} +#endif #endif /* CONSTELLATION_DISPLAY_PLOT_C */ diff --git a/gr-qtgui/lib/ConstellationDisplayPlot.h b/gr-qtgui/lib/ConstellationDisplayPlot.h index 23004f86c..d252a8c87 100644 --- a/gr-qtgui/lib/ConstellationDisplayPlot.h +++ b/gr-qtgui/lib/ConstellationDisplayPlot.h @@ -38,6 +38,11 @@ #include <qwt_symbol.h> #include <qtgui_util.h> +#if QWT_VERSION >= 0x060000 +#include <qwt_point_3d.h> // doesn't seem necessary, but is... +#include <qwt_compat.h> +#endif + class ConstellationDisplayPlot : public QwtPlot { Q_OBJECT @@ -62,7 +67,11 @@ public: public slots: void resizeSlot( QSize *s ); +#if QWT_VERSION < 0x060000 void OnPickerPointSelected(const QwtDoublePoint & p); +#else + void OnPickerPointSelected(const QPointF & p); +#endif signals: void plotPointSelected(const QPointF p); diff --git a/gr-qtgui/lib/FrequencyDisplayPlot.cc b/gr-qtgui/lib/FrequencyDisplayPlot.cc index f57edd8f6..2e62f2b96 100644 --- a/gr-qtgui/lib/FrequencyDisplayPlot.cc +++ b/gr-qtgui/lib/FrequencyDisplayPlot.cc @@ -133,11 +133,17 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) _xAxisPoints = new double[_numPoints]; // Disable polygon clipping +#if QWT_VERSION < 0x060000 QwtPainter::setDeviceClipping(false); +#else + QwtPainter::setPolylineSplitting(false); +#endif +#if QWT_VERSION < 0x060000 // We don't need the cache here canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false); +#endif QPalette palette; palette.setColor(canvas()->backgroundRole(), QColor("white")); @@ -156,18 +162,35 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) _fft_plot_curve = new QwtPlotCurve("Power Spectrum"); _fft_plot_curve->attach(this); _fft_plot_curve->setPen(QPen(Qt::blue)); + +#if QWT_VERSION < 0x060000 _fft_plot_curve->setRawData(_xAxisPoints, _dataPoints, _numPoints); +#else + _fft_plot_curve->setRawSamples(_xAxisPoints, _dataPoints, _numPoints); +#endif _min_fft_plot_curve = new QwtPlotCurve("Minimum Power"); _min_fft_plot_curve->attach(this); _min_fft_plot_curve->setPen(QPen(Qt::magenta)); + +#if QWT_VERSION < 0x060000 _min_fft_plot_curve->setRawData(_xAxisPoints, _minFFTPoints, _numPoints); +#else + _min_fft_plot_curve->setRawSamples(_xAxisPoints, _minFFTPoints, _numPoints); +#endif + _min_fft_plot_curve->setVisible(false); _max_fft_plot_curve = new QwtPlotCurve("Maximum Power"); _max_fft_plot_curve->attach(this); _max_fft_plot_curve->setPen(QPen(Qt::darkYellow)); + +#if QWT_VERSION < 0x060000 _max_fft_plot_curve->setRawData(_xAxisPoints, _maxFFTPoints, _numPoints); +#else + _max_fft_plot_curve->setRawSamples(_xAxisPoints, _maxFFTPoints, _numPoints); +#endif + _max_fft_plot_curve->setVisible(false); _lower_intensity_marker= new QwtPlotMarker(); @@ -197,9 +220,16 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) symbol.setSize(8); symbol.setPen(QPen(Qt::yellow)); symbol.setBrush(QBrush(Qt::yellow)); + +#if QWT_VERSION < 0x060000 _markerPeakAmplitude->setSymbol(symbol); - _markerPeakAmplitude->attach(this); +#else + _markerPeakAmplitude->setSymbol(&symbol); +#endif + /// THIS CAUSES A PROBLEM! + //_markerPeakAmplitude->attach(this); + _markerNoiseFloorAmplitude = new QwtPlotMarker(); _markerNoiseFloorAmplitude->setLineStyle(QwtPlotMarker::HLine); _markerNoiseFloorAmplitude->setLinePen(QPen(Qt::darkRed, 0, Qt::DotLine)); @@ -220,15 +250,25 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) // emit the position of clicks on widget _picker = new QwtDblClickPlotPicker(canvas()); + +#if QWT_VERSION < 0x060000 connect(_picker, SIGNAL(selected(const QwtDoublePoint &)), this, SLOT(OnPickerPointSelected(const QwtDoublePoint &))); +#else + connect(_picker, SIGNAL(selected(const QPointF &)), + this, SLOT(OnPickerPointSelected(const QPointF &))); +#endif // Configure magnify on mouse wheel _magnifier = new QwtPlotMagnifier(canvas()); _magnifier->setAxisEnabled(QwtPlot::xBottom, false); _zoomer = new FreqDisplayZoomer(canvas(), 0); + +#if QWT_VERSION < 0x060000 _zoomer->setSelectionFlags(QwtPicker::RectSelection | QwtPicker::DragSelection); +#endif + _zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier); _zoomer->setMousePattern(QwtEventPattern::MouseSelect3, @@ -362,7 +402,7 @@ FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDat { // Only update plot if there is data and if the time interval has elapsed if((numDataPoints > 0) && - (gruel::high_res_timer_now() - _lastReplot > timeInterval*gruel::high_res_timer_tps())) { + (gruel::high_res_timer_now() - _lastReplot > timeInterval*gruel::high_res_timer_tps())) { if(numDataPoints != _numPoints) { _numPoints = numDataPoints; @@ -375,16 +415,22 @@ FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDat _xAxisPoints = new double[_numPoints]; _minFFTPoints = new double[_numPoints]; _maxFFTPoints = new double[_numPoints]; - + +#if QWT_VERSION < 0x060000 _fft_plot_curve->setRawData(_xAxisPoints, _dataPoints, _numPoints); _min_fft_plot_curve->setRawData(_xAxisPoints, _minFFTPoints, _numPoints); _max_fft_plot_curve->setRawData(_xAxisPoints, _maxFFTPoints, _numPoints); +#else + _fft_plot_curve->setRawSamples(_xAxisPoints, _dataPoints, _numPoints); + _min_fft_plot_curve->setRawSamples(_xAxisPoints, _minFFTPoints, _numPoints); + _max_fft_plot_curve->setRawSamples(_xAxisPoints, _maxFFTPoints, _numPoints); +#endif _resetXAxisPoints(); ClearMaxData(); ClearMinData(); } - + memcpy(_dataPoints, dataPoints, numDataPoints*sizeof(double)); for(int64_t point = 0; point < numDataPoints; point++){ if(dataPoints[point] < _minFFTPoints[point]){ @@ -401,6 +447,8 @@ FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDat SetUpperIntensityLevel(_peakAmplitude); + replot(); + _lastReplot = gruel::high_res_timer_now(); } } @@ -478,7 +526,7 @@ FrequencyDisplayPlot::SetBGColour (QColor c) { QPalette palette; palette.setColor(canvas()->backgroundRole(), c); - canvas()->setPalette(palette); + canvas()->setPalette(palette); } void @@ -490,6 +538,7 @@ FrequencyDisplayPlot::ShowCFMarker (const bool show) _markerCF->hide(); } +#if QWT_VERSION < 0x060000 void FrequencyDisplayPlot::OnPickerPointSelected(const QwtDoublePoint & p) { @@ -498,5 +547,15 @@ FrequencyDisplayPlot::OnPickerPointSelected(const QwtDoublePoint & p) point.setX(point.x() * _xAxisMultiplier); emit plotPointSelected(point); } +#else +void +FrequencyDisplayPlot::OnPickerPointSelected(const QPointF & p) +{ + QPointF point = p; + //fprintf(stderr,"OnPickerPointSelected %f %f %d\n", point.x(), point.y(), _xAxisMultiplier); + point.setX(point.x() * _xAxisMultiplier); + emit plotPointSelected(point); +} +#endif #endif /* FREQUENCY_DISPLAY_PLOT_C */ diff --git a/gr-qtgui/lib/FrequencyDisplayPlot.h b/gr-qtgui/lib/FrequencyDisplayPlot.h index a263fec2f..961f30168 100644 --- a/gr-qtgui/lib/FrequencyDisplayPlot.h +++ b/gr-qtgui/lib/FrequencyDisplayPlot.h @@ -39,6 +39,10 @@ #include <qwt_symbol.h> #include <qtgui_util.h> +#if QWT_VERSION >= 0x060000 +#include <qwt_compat.h> +#endif + class FrequencyDisplayPlot:public QwtPlot{ Q_OBJECT @@ -76,7 +80,11 @@ public slots: void SetLowerIntensityLevel(const double); void SetUpperIntensityLevel(const double); +#if QWT_VERSION < 0x060000 void OnPickerPointSelected(const QwtDoublePoint & p); +#else + void OnPickerPointSelected(const QPointF & p); +#endif signals: void plotPointSelected(const QPointF p); @@ -107,6 +115,7 @@ private: QwtPlotMarker *_markerCF; QwtDblClickPlotPicker *_picker; + QwtPlotMagnifier *_magnifier; double* _dataPoints; diff --git a/gr-qtgui/lib/Makefile.am b/gr-qtgui/lib/Makefile.am index 849ee8360..aba311297 100644 --- a/gr-qtgui/lib/Makefile.am +++ b/gr-qtgui/lib/Makefile.am @@ -24,8 +24,8 @@ include $(top_srcdir)/Makefile.common EXTRA_DIST += spectrumdisplayform.ui AM_CPPFLAGS = -I. $(STD_DEFINES_AND_INCLUDES) $(PYTHON_CPPFLAGS) \ - $(QT_INCLUDES) $(BOOST_CPPFLAGS) $(WITH_INCLUDES) \ - -Dlibgnuradio_qtgui_EXPORTS + $(QT_INCLUDES) $(BOOST_CPPFLAGS) $(GR_QTGUI_INCLUDES) \ + $(WITH_INCLUDES) -Dlibgnuradio_qtgui_EXPORTS # Only include these files in the build if qtgui passes configure checks # This is mostly to help make distcheck pass @@ -70,17 +70,11 @@ grinclude_HEADERS = \ WaterfallDisplayPlot.h \ waterfallGlobalData.h \ ConstellationDisplayPlot.h \ - plot_waterfall.h \ spectrumdisplayform.h \ timedisplayform.h \ SpectrumGUIClass.h \ - spectrumUpdateEvents.h \ - gr_qtgui_api.h \ - qtgui_sink_c.h \ - qtgui_sink_f.h \ - qtgui_time_sink_c.h \ - qtgui_time_sink_f.h \ - qtgui_util.h + plot_waterfall.h \ + spectrumUpdateEvents.h #QT_MOC_FLAGS=-DQT_SHARED -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB QT_MOC_FLAGS=-DQT_SHARED -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index f635a2b0c..eca6076b6 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -103,14 +103,23 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) memset(_xAxisPoints, 0x0, _numPoints*sizeof(double)); _zoomer = new TimeDomainDisplayZoomer(canvas(), 0); + +#if QWT_VERSION < 0x060000 _zoomer->setSelectionFlags(QwtPicker::RectSelection | QwtPicker::DragSelection); +#endif // Disable polygon clipping +#if QWT_VERSION < 0x060000 QwtPainter::setDeviceClipping(false); +#else + QwtPainter::setPolylineSplitting(false); +#endif +#if QWT_VERSION < 0x060000 // We don't need the cache here canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false); +#endif QPalette palette; palette.setColor(canvas()->backgroundRole(), QColor("white")); @@ -130,8 +139,6 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) << QColor(Qt::yellow) << QColor(Qt::gray) << QColor(Qt::darkRed) << QColor(Qt::darkGreen) << QColor(Qt::darkBlue) << QColor(Qt::darkGray); - int ncolors = colors.size(); - // Setup dataPoints and plot vectors // Automatically deleted when parent is deleted for(int i = 0; i < _nplots; i++) { @@ -141,8 +148,13 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) _plot_curve.push_back(new QwtPlotCurve(QString("Data %1").arg(i))); _plot_curve[i]->attach(this); _plot_curve[i]->setPen(QPen(colors[i])); + +#if QWT_VERSION < 0x060000 _plot_curve[i]->setRawData(_xAxisPoints, _dataPoints[i], _numPoints); - } +#else + _plot_curve[i]->setRawSamples(_xAxisPoints, _dataPoints[i], _numPoints); +#endif +} _sampleRate = 1; _resetXAxisPoints(); @@ -158,8 +170,14 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) // emit the position of clicks on widget _picker = new QwtDblClickPlotPicker(canvas()); + +#if QWT_VERSION < 0x060000 connect(_picker, SIGNAL(selected(const QwtDoublePoint &)), this, SLOT(OnPickerPointSelected(const QwtDoublePoint &))); +#else + connect(_picker, SIGNAL(selected(const QPointF &)), + this, SLOT(OnPickerPointSelected(const QPointF &))); +#endif // Configure magnify on mouse wheel _magnifier = new QwtPlotMagnifier(canvas()); @@ -245,7 +263,12 @@ void TimeDomainDisplayPlot::PlotNewData(const std::vector<double*> dataPoints, for(int i = 0; i < _nplots; i++) { delete[] _dataPoints[i]; _dataPoints[i] = new double[_numPoints]; + +#if QWT_VERSION < 0x060000 _plot_curve[i]->setRawData(_xAxisPoints, _dataPoints[i], _numPoints); +#else + _plot_curve[i]->setRawSamples(_xAxisPoints, _dataPoints[i], _numPoints); +#endif } setXaxis(0, numDataPoints); @@ -255,6 +278,8 @@ void TimeDomainDisplayPlot::PlotNewData(const std::vector<double*> dataPoints, for(int i = 0; i < _nplots; i++) { memcpy(_dataPoints[i], dataPoints[i], numDataPoints*sizeof(double)); } + + replot(); } } @@ -300,6 +325,8 @@ TimeDomainDisplayPlot::SetSampleRate(double sr, double units, } } + +#if QWT_VERSION < 0x060000 void TimeDomainDisplayPlot::OnPickerPointSelected(const QwtDoublePoint & p) { @@ -307,5 +334,14 @@ TimeDomainDisplayPlot::OnPickerPointSelected(const QwtDoublePoint & p) //fprintf(stderr,"OnPickerPointSelected %f %f\n", point.x(), point.y()); emit plotPointSelected(point); } +#else +void +TimeDomainDisplayPlot::OnPickerPointSelected(const QPointF & p) +{ + QPointF point = p; + //fprintf(stderr,"OnPickerPointSelected %f %f\n", point.x(), point.y()); + emit plotPointSelected(point); +} +#endif #endif /* TIME_DOMAIN_DISPLAY_PLOT_C */ diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.h b/gr-qtgui/lib/TimeDomainDisplayPlot.h index af87e1b14..6c7fc4330 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.h +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.h @@ -39,6 +39,10 @@ #include <qwt_symbol.h> #include <qtgui_util.h> +#if QWT_VERSION >= 0x060000 +#include <qwt_compat.h> +#endif + class TimeDomainDisplayPlot:public QwtPlot{ Q_OBJECT @@ -61,7 +65,11 @@ public slots: void SetSampleRate(double sr, double units, const std::string &strunits); +#if QWT_VERSION < 0x060000 void OnPickerPointSelected(const QwtDoublePoint & p); +#else + void OnPickerPointSelected(const QPointF & p); +#endif signals: void plotPointSelected(const QPointF p); diff --git a/gr-qtgui/lib/WaterfallDisplayPlot.cc b/gr-qtgui/lib/WaterfallDisplayPlot.cc index 1476be2bd..94a8e6210 100644 --- a/gr-qtgui/lib/WaterfallDisplayPlot.cc +++ b/gr-qtgui/lib/WaterfallDisplayPlot.cc @@ -230,6 +230,58 @@ private: std::string _unitType; }; +class ColorMap_MultiColor: public QwtLinearColorMap +{ +public: + ColorMap_MultiColor(): + QwtLinearColorMap(Qt::darkCyan, Qt::white) + { + addColorStop(0.25, Qt::cyan); + addColorStop(0.5, Qt::yellow); + addColorStop(0.75, Qt::red); + } +}; + +class ColorMap_WhiteHot: public QwtLinearColorMap +{ +public: + ColorMap_WhiteHot(): + QwtLinearColorMap(Qt::black, Qt::white) + { + } +}; + +class ColorMap_BlackHot: public QwtLinearColorMap +{ +public: + ColorMap_BlackHot(): + QwtLinearColorMap(Qt::white, Qt::black) + { + } +}; + +class ColorMap_Incandescent: public QwtLinearColorMap +{ +public: + ColorMap_Incandescent(): + QwtLinearColorMap(Qt::black, Qt::white) + { + addColorStop(0.5, Qt::darkRed); + } +}; + +class ColorMap_UserDefined: public QwtLinearColorMap +{ +public: + ColorMap_UserDefined(QColor low, QColor high): + QwtLinearColorMap(low, high) + { + } +}; + +/********************************************************************* +MAIN WATERFALL PLOT WIDGET +*********************************************************************/ WaterfallDisplayPlot::WaterfallDisplayPlot(QWidget* parent) : QwtPlot(parent) @@ -241,8 +293,6 @@ WaterfallDisplayPlot::WaterfallDisplayPlot(QWidget* parent) resize(parent->width(), parent->height()); _numPoints = 1024; - _waterfallData = new WaterfallData(_startFrequency, _stopFrequency, _numPoints, 200); - QPalette palette; palette.setColor(canvas()->backgroundRole(), QColor("white")); canvas()->setPalette(palette); @@ -255,26 +305,34 @@ WaterfallDisplayPlot::WaterfallDisplayPlot(QWidget* parent) _lastReplot = 0; - d_spectrogram = new PlotWaterfall(_waterfallData, "Waterfall Display"); - _intensityColorMapType = INTENSITY_COLOR_MAP_TYPE_MULTI_COLOR; - QwtLinearColorMap colorMap(Qt::darkCyan, Qt::white); - colorMap.addColorStop(0.25, Qt::cyan); - colorMap.addColorStop(0.5, Qt::yellow); - colorMap.addColorStop(0.75, Qt::red); + d_data = new WaterfallData(_startFrequency, _stopFrequency, + _numPoints, 200); + +#if QWT_VERSION < 0x060000 + d_spectrogram = new PlotWaterfall(d_data, "Waterfall Display"); + ColorMap_MultiColor colorMap; d_spectrogram->setColorMap(colorMap); - + +#else + d_spectrogram = new QwtPlotSpectrogram("Spectrogram"); + d_spectrogram->setData(d_data); + d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ImageMode, true); + d_spectrogram->setColorMap(new ColorMap_MultiColor()); +#endif + d_spectrogram->attach(this); // LeftButton for the zooming // MidButton for the panning // RightButton: zoom out by 1 // Ctrl+RighButton: zoom out to full size - _zoomer = new WaterfallZoomer(canvas(), 0); +#if QWT_VERSION < 0x060000 _zoomer->setSelectionFlags(QwtPicker::RectSelection | QwtPicker::DragSelection); +#endif _zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier); _zoomer->setMousePattern(QwtEventPattern::MouseSelect3, @@ -286,9 +344,14 @@ WaterfallDisplayPlot::WaterfallDisplayPlot(QWidget* parent) // emit the position of clicks on widget _picker = new QwtDblClickPlotPicker(canvas()); +#if QWT_VERSION < 0x060000 connect(_picker, SIGNAL(selected(const QwtDoublePoint &)), this, SLOT(OnPickerPointSelected(const QwtDoublePoint &))); - +#else + connect(_picker, SIGNAL(selected(const QPointF &)), + this, SLOT(OnPickerPointSelected(const QPointF &))); +#endif + // Avoid jumping when labels with more/less digits // appear/disappear when scrolling vertically @@ -296,7 +359,7 @@ WaterfallDisplayPlot::WaterfallDisplayPlot(QWidget* parent) QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft); sd->setMinimumExtent( fm.width("100.00") ); - const QColor c(Qt::white); + const QColor c(Qt::black); _zoomer->setRubberBandPen(c); _zoomer->setTrackerPen(c); @@ -307,15 +370,15 @@ WaterfallDisplayPlot::WaterfallDisplayPlot(QWidget* parent) WaterfallDisplayPlot::~WaterfallDisplayPlot() { - delete _waterfallData; + delete d_data; delete d_spectrogram; } void WaterfallDisplayPlot::Reset() { - _waterfallData->ResizeData(_startFrequency, _stopFrequency, _numPoints); - _waterfallData->Reset(); + d_data->ResizeData(_startFrequency, _stopFrequency, _numPoints); + d_data->Reset(); setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency); @@ -408,9 +471,8 @@ WaterfallDisplayPlot::PlotNewData(const double* dataPoints, } if(gruel::high_res_timer_now() - _lastReplot > timePerFFT*gruel::high_res_timer_tps()) { - //FIXME: We may want to average the data between these updates to smooth display - _waterfallData->addFFTData(dataPoints, numDataPoints, droppedFrames); - _waterfallData->IncrementNumLinesToUpdate(); + d_data->addFFTData(dataPoints, numDataPoints, droppedFrames); + d_data->IncrementNumLinesToUpdate(); QwtTimeScaleDraw* timeScale = (QwtTimeScaleDraw*)axisScaleDraw(QwtPlot::yLeft); timeScale->SetSecondsPerLine(timePerFFT); @@ -421,7 +483,7 @@ WaterfallDisplayPlot::PlotNewData(const double* dataPoints, d_spectrogram->invalidateCache(); d_spectrogram->itemChanged(); - + replot(); _lastReplot = gruel::high_res_timer_now(); @@ -431,9 +493,13 @@ WaterfallDisplayPlot::PlotNewData(const double* dataPoints, void WaterfallDisplayPlot::SetIntensityRange(const double minIntensity, - const double maxIntensity) + const double maxIntensity) { - _waterfallData->setRange(QwtDoubleInterval(minIntensity, maxIntensity)); +#if QWT_VERSION < 0x060000 + d_data->setRange(QwtDoubleInterval(minIntensity, maxIntensity)); +#else + d_data->setInterval(Qt::ZAxis, QwtInterval(minIntensity, maxIntensity)); +#endif emit UpdatedLowerIntensityLevel(minIntensity); emit UpdatedUpperIntensityLevel(maxIntensity); @@ -447,7 +513,8 @@ WaterfallDisplayPlot::replot() QwtTimeScaleDraw* timeScale = (QwtTimeScaleDraw*)axisScaleDraw(QwtPlot::yLeft); timeScale->initiateUpdate(); - WaterfallFreqDisplayScaleDraw* freqScale = (WaterfallFreqDisplayScaleDraw*)axisScaleDraw(QwtPlot::xBottom); + WaterfallFreqDisplayScaleDraw* freqScale = \ + (WaterfallFreqDisplayScaleDraw*)axisScaleDraw(QwtPlot::xBottom); freqScale->initiateUpdate(); // Update the time axis display @@ -490,38 +557,54 @@ WaterfallDisplayPlot::SetIntensityColorMapType(const int newType, switch(newType){ case INTENSITY_COLOR_MAP_TYPE_MULTI_COLOR:{ _intensityColorMapType = newType; - QwtLinearColorMap colorMap(Qt::darkCyan, Qt::white); - colorMap.addColorStop(0.25, Qt::cyan); - colorMap.addColorStop(0.5, Qt::yellow); - colorMap.addColorStop(0.75, Qt::red); +#if QWT_VERSION < 0x060000 + ColorMap_MultiColor colorMap; d_spectrogram->setColorMap(colorMap); +#else + d_spectrogram->setColorMap(new ColorMap_MultiColor()); +#endif break; } case INTENSITY_COLOR_MAP_TYPE_WHITE_HOT:{ _intensityColorMapType = newType; - QwtLinearColorMap colorMap(Qt::black, Qt::white); +#if QWT_VERSION < 0x060000 + ColorMap_WhiteHot colorMap; d_spectrogram->setColorMap(colorMap); +#else + d_spectrogram->setColorMap(new ColorMap_WhiteHot()); +#endif break; } case INTENSITY_COLOR_MAP_TYPE_BLACK_HOT:{ _intensityColorMapType = newType; - QwtLinearColorMap colorMap(Qt::white, Qt::black); +#if QWT_VERSION < 0x060000 + ColorMap_BlackHot colorMap; d_spectrogram->setColorMap(colorMap); +#else + d_spectrogram->setColorMap(new ColorMap_BlackHot()); +#endif break; } case INTENSITY_COLOR_MAP_TYPE_INCANDESCENT:{ _intensityColorMapType = newType; - QwtLinearColorMap colorMap(Qt::black, Qt::white); - colorMap.addColorStop(0.5, Qt::darkRed); +#if QWT_VERSION < 0x060000 + ColorMap_Incandescent colorMap; d_spectrogram->setColorMap(colorMap); +#else + d_spectrogram->setColorMap(new ColorMap_Incandescent()); +#endif break; } case INTENSITY_COLOR_MAP_TYPE_USER_DEFINED:{ _userDefinedLowIntensityColor = lowColor; _userDefinedHighIntensityColor = highColor; _intensityColorMapType = newType; - QwtLinearColorMap colorMap(_userDefinedLowIntensityColor, _userDefinedHighIntensityColor); +#if QWT_VERSION < 0x060000 + ColorMap_UserDefined colorMap(lowColor, highColor); d_spectrogram->setColorMap(colorMap); +#else + d_spectrogram->setColorMap(new ColorMap_UserDefined(lowColor, highColor)); +#endif break; } default: break; @@ -549,12 +632,33 @@ WaterfallDisplayPlot::_UpdateIntensityRangeDisplay() QwtScaleWidget *rightAxis = axisWidget(QwtPlot::yRight); rightAxis->setTitle("Intensity (dB)"); rightAxis->setColorBarEnabled(true); + +#if QWT_VERSION < 0x060000 rightAxis->setColorMap(d_spectrogram->data()->range(), d_spectrogram->colorMap()); - setAxisScale(QwtPlot::yRight, d_spectrogram->data()->range().minValue(), - d_spectrogram->data()->range().maxValue() ); + d_spectrogram->data()->range().maxValue()); +#else + QwtInterval intv = d_spectrogram->interval(Qt::ZAxis); + switch(_intensityColorMapType) { + case INTENSITY_COLOR_MAP_TYPE_MULTI_COLOR: + rightAxis->setColorMap(intv, new ColorMap_MultiColor()); break; + case INTENSITY_COLOR_MAP_TYPE_WHITE_HOT: + rightAxis->setColorMap(intv, new ColorMap_WhiteHot()); break; + case INTENSITY_COLOR_MAP_TYPE_BLACK_HOT: + rightAxis->setColorMap(intv, new ColorMap_BlackHot()); break; + case INTENSITY_COLOR_MAP_TYPE_INCANDESCENT: + rightAxis->setColorMap(intv, new ColorMap_Incandescent()); break; + case INTENSITY_COLOR_MAP_TYPE_USER_DEFINED: + rightAxis->setColorMap(intv, new ColorMap_UserDefined(_userDefinedLowIntensityColor, + _userDefinedHighIntensityColor)); break; + default: + rightAxis->setColorMap(intv, new ColorMap_MultiColor()); break; + } + setAxisScale(QwtPlot::yRight, intv.minValue(), intv.maxValue()); +#endif + enableAxis(QwtPlot::yRight); plotLayout()->setAlignCanvasToScales(true); @@ -570,13 +674,24 @@ WaterfallDisplayPlot::_UpdateIntensityRangeDisplay() _lastReplot = gruel::high_res_timer_now(); } +#if QWT_VERSION < 0x060000 void WaterfallDisplayPlot::OnPickerPointSelected(const QwtDoublePoint & p) { QPointF point = p; - //fprintf(stderr,"OnPickerPointSelected %f %f %d\n", point.x(), point.y(), _xAxisMultiplier); + //fprintf(stderr,"OnPickerPointSelected %f %f\n", point.x(), point.y()); + point.setX(point.x() * _xAxisMultiplier); + emit plotPointSelected(point); +} +#else +void +WaterfallDisplayPlot::OnPickerPointSelected(const QPointF & p) +{ + QPointF point = p; + //fprintf(stderr,"OnPickerPointSelected %f %f\n", point.x(), point.y()); point.setX(point.x() * _xAxisMultiplier); emit plotPointSelected(point); } +#endif #endif /* WATERFALL_DISPLAY_PLOT_C */ diff --git a/gr-qtgui/lib/WaterfallDisplayPlot.h b/gr-qtgui/lib/WaterfallDisplayPlot.h index 0c6a521b1..0458597b0 100644 --- a/gr-qtgui/lib/WaterfallDisplayPlot.h +++ b/gr-qtgui/lib/WaterfallDisplayPlot.h @@ -26,14 +26,20 @@ #include <stdint.h> #include <cstdio> #include <qwt_plot.h> +#include <qwt_plot_spectrogram.h> #include <qwt_plot_zoomer.h> #include <qwt_plot_panner.h> - #include <qtgui_util.h> -#include <plot_waterfall.h> +#include <waterfallGlobalData.h> #include <gruel/high_res_timer.h> +#if QWT_VERSION < 0x060000 +#include <plot_waterfall.h> +#else +#include <qwt_compat.h> +#endif + class WaterfallDisplayPlot:public QwtPlot{ Q_OBJECT @@ -73,7 +79,12 @@ public: public slots: void resizeSlot( QSize *s ); + +#if QWT_VERSION < 0x060000 void OnPickerPointSelected(const QwtDoublePoint & p); +#else + void OnPickerPointSelected(const QPointF & p); +#endif signals: void UpdatedLowerIntensityLevel(const double); @@ -89,14 +100,18 @@ private: double _stopFrequency; int _xAxisMultiplier; - PlotWaterfall *d_spectrogram; - QwtPlotPanner* _panner; QwtPlotZoomer* _zoomer; QwtDblClickPlotPicker *_picker; - WaterfallData* _waterfallData; + WaterfallData *d_data; + +#if QWT_VERSION < 0x060000 + PlotWaterfall *d_spectrogram; +#else + QwtPlotSpectrogram *d_spectrogram; +#endif gruel::high_res_timer_type _lastReplot; diff --git a/gr-qtgui/lib/plot_waterfall.cc b/gr-qtgui/lib/plot_waterfall.cc index 2b1447e03..dbba657b8 100644 --- a/gr-qtgui/lib/plot_waterfall.cc +++ b/gr-qtgui/lib/plot_waterfall.cc @@ -2,85 +2,52 @@ #include <qpen.h> #include <qpainter.h> #include "qwt_painter.h" -#include "qwt_double_interval.h" #include "qwt_scale_map.h" #include "qwt_color_map.h" #include "plot_waterfall.h" -#if QT_VERSION < 0x040000 -typedef Q3ValueVector<QRgb> QwtColorTable; -#else -typedef QVector<QRgb> QwtColorTable; +#if QWT_VERSION < 0x060000 +#include "qwt_double_interval.h" #endif +typedef QVector<QRgb> QwtColorTable; class PlotWaterfallImage: public QImage { // This class hides some Qt3/Qt4 API differences public: PlotWaterfallImage(const QSize &size, QwtColorMap::Format format): -#if QT_VERSION < 0x040000 - QImage(size, format == QwtColorMap::RGB ? 32 : 8) -#else - QImage(size, format == QwtColorMap::RGB - ? QImage::Format_ARGB32 : QImage::Format_Indexed8 ) -#endif - { - } - - PlotWaterfallImage(const QImage &other): - QImage(other) - { - } - - void initColorTable(const QImage& other) - { -#if QT_VERSION < 0x040000 - const unsigned int numColors = other.numColors(); - - setNumColors(numColors); - for ( unsigned int i = 0; i < numColors; i++ ) - setColor(i, other.color(i)); -#else - setColorTable(other.colorTable()); -#endif - } - -#if QT_VERSION < 0x040000 - - void setColorTable(const QwtColorTable &colorTable) - { - setNumColors(colorTable.size()); - for ( unsigned int i = 0; i < colorTable.size(); i++ ) - setColor(i, colorTable[i]); - } - - QwtColorTable colorTable() const - { - QwtColorTable table(numColors()); - for ( int i = 0; i < numColors(); i++ ) - table[i] = color(i); - - return table; - } -#endif + QImage(size, format == QwtColorMap::RGB + ? QImage::Format_ARGB32 : QImage::Format_Indexed8 ) + { + } + + PlotWaterfallImage(const QImage &other): + QImage(other) + { + } + + void initColorTable(const QImage& other) + { + setColorTable(other.colorTable()); + } }; class PlotWaterfall::PrivateData { public: - PrivateData() - { - data = NULL; - colorMap = new QwtLinearColorMap(); - } - ~PrivateData() - { - delete colorMap; - } - - WaterfallData *data; - QwtColorMap *colorMap; + PrivateData() + { + data = NULL; + colorMap = new QwtLinearColorMap(); + } + ~PrivateData() + { + delete colorMap; + } + + WaterfallData *data; + QwtColorMap *colorMap; }; /*! @@ -138,7 +105,9 @@ int PlotWaterfall::rtti() const void PlotWaterfall::setColorMap(const QwtColorMap &colorMap) { delete d_data->colorMap; +#if QWT_VERSION < 0x060000 d_data->colorMap = colorMap.copy(); +#endif invalidateCache(); itemChanged(); @@ -150,16 +119,19 @@ void PlotWaterfall::setColorMap(const QwtColorMap &colorMap) */ const QwtColorMap &PlotWaterfall::colorMap() const { - return *d_data->colorMap; + return *d_data->colorMap; } + /*! \return Bounding rect of the data \sa QwtRasterData::boundingRect */ +#if QWT_VERSION < 0x060000 QwtDoubleRect PlotWaterfall::boundingRect() const { - return d_data->data->boundingRect(); + return d_data->data->boundingRect(); } +#endif /*! \brief Returns the recommended raster for a given rect. @@ -170,10 +142,12 @@ QwtDoubleRect PlotWaterfall::boundingRect() const \param rect Rect for the raster hint \return data().rasterHint(rect) */ +#if QWT_VERSION < 0x060000 QSize PlotWaterfall::rasterHint(const QwtDoubleRect &rect) const { - return d_data->data->rasterHint(rect); + return d_data->data->rasterHint(rect); } +#endif /*! \brief Render an image from the data and color map. @@ -192,19 +166,31 @@ QSize PlotWaterfall::rasterHint(const QwtDoubleRect &rect) const \sa QwtRasterData::intensity(), QwtColorMap::rgb(), QwtColorMap::colorIndex() */ -QImage PlotWaterfall::renderImage( - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - const QwtDoubleRect &area) const +#if QWT_VERSION < 0x060000 +QImage PlotWaterfall::renderImage(const QwtScaleMap &xMap, + const QwtScaleMap &yMap, + const QwtDoubleRect &area) const +#else +QImage PlotWaterfall::renderImage(const QwtScaleMap &xMap, + const QwtScaleMap &yMap, + const QRectF &area, + const QSize &size) const +#endif { if ( area.isEmpty() ) return QImage(); +#if QWT_VERSION < 0x060000 QRect rect = transform(xMap, yMap, area); + const QSize res = d_data->data->rasterHint(area); +#else + QRect rect(0,0,0,0); + const QSize res(0,0); +#endif QwtScaleMap xxMap = xMap; QwtScaleMap yyMap = yMap; - const QSize res = d_data->data->rasterHint(area); if ( res.isValid() ) { /* @@ -243,7 +229,11 @@ QImage PlotWaterfall::renderImage( PlotWaterfallImage image(rect.size(), d_data->colorMap->format()); +#if QWT_VERSION < 0x060000 const QwtDoubleInterval intensityRange = d_data->data->range(); +#else + const QwtInterval intensityRange = d_data->data->interval(Qt::ZAxis); +#endif if ( !intensityRange.isValid() ) return image; @@ -292,13 +282,7 @@ QImage PlotWaterfall::renderImage( const bool vInvert = yyMap.p1() < yyMap.p2(); if ( hInvert || vInvert ) { -#ifdef __GNUC__ -#endif -#if QT_VERSION < 0x040000 - image = image.mirror(hInvert, vInvert); -#else - image = image.mirrored(hInvert, vInvert); -#endif + image = image.mirrored(hInvert, vInvert); } return image; @@ -317,7 +301,8 @@ QImage PlotWaterfall::renderImage( */ void PlotWaterfall::draw(QPainter *painter, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QwtScaleMap &xMap, + const QwtScaleMap &yMap, const QRect &canvasRect) const { QwtPlotRasterItem::draw(painter, xMap, yMap, canvasRect); diff --git a/gr-qtgui/lib/plot_waterfall.h b/gr-qtgui/lib/plot_waterfall.h index a11461611..1613dd8de 100644 --- a/gr-qtgui/lib/plot_waterfall.h +++ b/gr-qtgui/lib/plot_waterfall.h @@ -3,9 +3,12 @@ #include <qglobal.h> #include <waterfallGlobalData.h> +#include <qwt_plot_rasteritem.h> -#include "qwt_valuelist.h" -#include "qwt_plot_rasteritem.h" +#if QWT_VERSION >= 0x060000 +#include <qwt_point_3d.h> // doesn't seem necessary, but is... +#include <qwt_compat.h> +#endif class QwtColorMap; @@ -22,27 +25,39 @@ class QwtColorMap; class PlotWaterfall: public QwtPlotRasterItem { public: - explicit PlotWaterfall(WaterfallData* data, const QString &title = QString::null); + explicit PlotWaterfall(WaterfallData* data, + const QString &title = QString::null); virtual ~PlotWaterfall(); const WaterfallData* data()const; void setColorMap(const QwtColorMap &); + const QwtColorMap &colorMap() const; +#if QWT_VERSION < 0x060000 virtual QwtDoubleRect boundingRect() const; virtual QSize rasterHint(const QwtDoubleRect &) const; +#endif virtual int rtti() const; virtual void draw(QPainter *p, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - const QRect &rect) const; + const QwtScaleMap &xMap, + const QwtScaleMap &yMap, + const QRect &rect) const; protected: - virtual QImage renderImage( - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - const QwtDoubleRect &rect) const; +#if QWT_VERSION < 0x060000 + QImage renderImage(const QwtScaleMap &xMap, + const QwtScaleMap &yMap, + const QwtDoubleRect &rect) const; +#else + QImage renderImage(const QwtScaleMap &xMap, + const QwtScaleMap &yMap, + const QRectF &rect, + const QSize &size=QSize(0,0)) const; +#endif private: class PrivateData; diff --git a/gr-qtgui/lib/qtgui_util.cc b/gr-qtgui/lib/qtgui_util.cc index 87b90997a..543ce1b1c 100644 --- a/gr-qtgui/lib/qtgui_util.cc +++ b/gr-qtgui/lib/qtgui_util.cc @@ -22,17 +22,24 @@ #include <qtgui_util.h> +#if QWT_VERSION < 0x060000 QwtPickerDblClickPointMachine::QwtPickerDblClickPointMachine() : QwtPickerMachine () { - } +#else +QwtPickerDblClickPointMachine::QwtPickerDblClickPointMachine() + : QwtPickerMachine (PointSelection) +{ +} +#endif QwtPickerDblClickPointMachine::~QwtPickerDblClickPointMachine() { } +#if QWT_VERSION < 0x060000 QwtPickerMachine::CommandList QwtPickerDblClickPointMachine::transition(const QwtEventPattern &eventPattern, const QEvent *e) @@ -53,10 +60,35 @@ QwtPickerDblClickPointMachine::transition(const QwtEventPattern &eventPattern, return cmdList; } +#else + +QList<QwtPickerMachine::Command> +QwtPickerDblClickPointMachine::transition(const QwtEventPattern &eventPattern, + const QEvent *e) +{ + QList<QwtPickerMachine::Command> cmdList; + switch(e->type()) { + case QEvent::MouseButtonDblClick: + if ( eventPattern.mouseMatch(QwtEventPattern::MouseSelect1, + (const QMouseEvent *)e) ) { + cmdList += QwtPickerMachine::Begin; + cmdList += QwtPickerMachine::Append; + cmdList += QwtPickerMachine::End; + } + break; + default: + break; + } + return cmdList; +} +#endif + QwtDblClickPlotPicker::QwtDblClickPlotPicker(QwtPlotCanvas* canvas) : QwtPlotPicker(canvas) { +#if QWT_VERSION < 0x060000 setSelectionFlags(QwtPicker::PointSelection); +#endif } QwtDblClickPlotPicker::~QwtDblClickPlotPicker() diff --git a/gr-qtgui/lib/spectrumdisplayform.cc b/gr-qtgui/lib/spectrumdisplayform.cc index 0e8594029..9fe553557 100644 --- a/gr-qtgui/lib/spectrumdisplayform.cc +++ b/gr-qtgui/lib/spectrumdisplayform.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008,2009,2010,2011 Free Software Foundation, Inc. + * Copyright 2008-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -35,7 +35,6 @@ SpectrumDisplayForm::SpectrumDisplayForm(QWidget* parent) _intValidator->setBottom(0); _frequencyDisplayPlot = new FrequencyDisplayPlot(FrequencyPlotDisplayFrame); _waterfallDisplayPlot = new WaterfallDisplayPlot(WaterfallPlotDisplayFrame); - _timeDomainDisplayPlot = new TimeDomainDisplayPlot(2, TimeDomainDisplayFrame); _constellationDisplayPlot = new ConstellationDisplayPlot(ConstellationDisplayFrame); _numRealDataPoints = 1024; @@ -62,9 +61,9 @@ SpectrumDisplayForm::SpectrumDisplayForm(QWidget* parent) _noiseFloorAmplitude = -HUGE_VAL; connect(_waterfallDisplayPlot, SIGNAL(UpdatedLowerIntensityLevel(const double)), - _frequencyDisplayPlot, SLOT(SetLowerIntensityLevel(const double))); + _frequencyDisplayPlot, SLOT(SetLowerIntensityLevel(const double))); connect(_waterfallDisplayPlot, SIGNAL(UpdatedUpperIntensityLevel(const double)), - _frequencyDisplayPlot, SLOT(SetUpperIntensityLevel(const double))); + _frequencyDisplayPlot, SLOT(SetUpperIntensityLevel(const double))); _frequencyDisplayPlot->SetLowerIntensityLevel(-200); _frequencyDisplayPlot->SetUpperIntensityLevel(-200); @@ -90,16 +89,16 @@ SpectrumDisplayForm::SpectrumDisplayForm(QWidget* parent) // Connect double click signals up connect(_frequencyDisplayPlot, SIGNAL(plotPointSelected(const QPointF)), - this, SLOT(onFFTPlotPointSelected(const QPointF))); + this, SLOT(onFFTPlotPointSelected(const QPointF))); connect(_waterfallDisplayPlot, SIGNAL(plotPointSelected(const QPointF)), - this, SLOT(onWFallPlotPointSelected(const QPointF))); + this, SLOT(onWFallPlotPointSelected(const QPointF))); connect(_timeDomainDisplayPlot, SIGNAL(plotPointSelected(const QPointF)), - this, SLOT(onTimePlotPointSelected(const QPointF))); + this, SLOT(onTimePlotPointSelected(const QPointF))); connect(_constellationDisplayPlot, SIGNAL(plotPointSelected(const QPointF)), - this, SLOT(onConstPlotPointSelected(const QPointF))); + this, SLOT(onConstPlotPointSelected(const QPointF))); } SpectrumDisplayForm::~SpectrumDisplayForm() @@ -242,7 +241,7 @@ SpectrumDisplayForm::newFrequencyData( const SpectrumUpdateEvent* spectrumUpdate _timeDomainDisplayPlot->PlotNewData(timeDomainDataPoints, numTimeDomainDataPoints, d_update_time); - } + } if(tabindex == d_plot_constellation) { _constellationDisplayPlot->PlotNewData(realTimeDomainDataPoints, imagTimeDomainDataPoints, @@ -258,7 +257,6 @@ SpectrumDisplayForm::newFrequencyData( const SpectrumUpdateEvent* spectrumUpdate spectrumUpdateEvent->getDroppedFFTFrames()); } } - // Tell the system the GUI has been updated if(_systemSpecifiedFlag){ @@ -296,7 +294,6 @@ SpectrumDisplayForm::customEvent( QEvent * e) if(_systemSpecifiedFlag){ WindowComboBox->setCurrentIndex(_system->GetWindowType()); FFTSizeComboBox->setCurrentIndex(_system->GetFFTSizeIndex()); - //FFTSizeComboBox->setCurrentIndex(1); } waterfallMinimumIntensityChangedCB(WaterfallMinimumIntensityWheel->value()); @@ -466,7 +463,8 @@ SpectrumDisplayForm::_AverageHistory(const double* newBuffer) if(_historyEntryCount > static_cast<int>(_historyVector->size())){ _historyEntryCount = _historyVector->size(); } - _historyEntry = (++_historyEntry)%_historyVector->size(); + _historyEntry += 1; + _historyEntry = _historyEntry % _historyVector->size(); // Total up and then average the values double sum; diff --git a/gr-qtgui/lib/waterfallGlobalData.cc b/gr-qtgui/lib/waterfallGlobalData.cc index 1ba153f0d..04366a297 100644 --- a/gr-qtgui/lib/waterfallGlobalData.cc +++ b/gr-qtgui/lib/waterfallGlobalData.cc @@ -2,14 +2,19 @@ #define WATERFALL_GLOBAL_DATA_CPP #include <waterfallGlobalData.h> +#include <cstdio> WaterfallData::WaterfallData(const double minimumFrequency, const double maximumFrequency, const uint64_t fftPoints, const unsigned int historyExtent) +#if QWT_VERSION < 0x060000 : QwtRasterData(QwtDoubleRect(minimumFrequency /* X START */, 0 /* Y START */, maximumFrequency - minimumFrequency /* WIDTH */, static_cast<double>(historyExtent)/* HEIGHT */)) +#else + : QwtRasterData() +#endif { _intensityRange = QwtDoubleInterval(-200.0, 0.0); @@ -18,6 +23,12 @@ WaterfallData::WaterfallData(const double minimumFrequency, _spectrumData = new double[_fftPoints * _historyLength]; +#if QWT_VERSION >= 0x060000 + setInterval(Qt::XAxis, QwtInterval(minimumFrequency, maximumFrequency)); + setInterval(Qt::YAxis, QwtInterval(0, historyExtent)); + setInterval(Qt::ZAxis, QwtInterval(-200, 0.0)); +#endif + Reset(); } @@ -35,6 +46,7 @@ void WaterfallData::Reset() void WaterfallData::Copy(const WaterfallData* rhs) { +#if QWT_VERSION < 0x060000 if((_fftPoints != rhs->GetNumFFTPoints()) || (boundingRect() != rhs->boundingRect()) ){ _fftPoints = rhs->GetNumFFTPoints(); @@ -42,38 +54,78 @@ void WaterfallData::Copy(const WaterfallData* rhs) delete[] _spectrumData; _spectrumData = new double[_fftPoints * _historyLength]; } +#else + if(_fftPoints != rhs->GetNumFFTPoints()) { + _fftPoints = rhs->GetNumFFTPoints(); + delete[] _spectrumData; + _spectrumData = new double[_fftPoints * _historyLength]; + } +#endif + Reset(); SetSpectrumDataBuffer(rhs->GetSpectrumDataBuffer()); SetNumLinesToUpdate(rhs->GetNumLinesToUpdate()); + +#if QWT_VERSION < 0x060000 setRange(rhs->range()); +#else + setInterval(Qt::XAxis, rhs->interval(Qt::XAxis)); + setInterval(Qt::YAxis, rhs->interval(Qt::YAxis)); + setInterval(Qt::ZAxis, rhs->interval(Qt::ZAxis)); +#endif } void WaterfallData::ResizeData(const double startFreq, const double stopFreq, const uint64_t fftPoints) { +#if QWT_VERSION < 0x060000 if((fftPoints != GetNumFFTPoints()) || (boundingRect().width() != (stopFreq - startFreq)) || (boundingRect().left() != startFreq)){ + + setBoundingRect(QwtDoubleRect(startFreq, 0, + stopFreq-startFreq, + boundingRect().height())); + _fftPoints = fftPoints; + delete[] _spectrumData; + _spectrumData = new double[_fftPoints * _historyLength]; + } + +#else + if((fftPoints != GetNumFFTPoints()) || + (interval(Qt::XAxis).width() != (stopFreq - startFreq)) || + (interval(Qt::XAxis).minValue() != startFreq)){ + + setInterval(Qt::XAxis, QwtInterval(startFreq, stopFreq)); - setBoundingRect(QwtDoubleRect(startFreq, 0, stopFreq-startFreq, boundingRect().height())); _fftPoints = fftPoints; delete[] _spectrumData; _spectrumData = new double[_fftPoints * _historyLength]; } - +#endif + Reset(); } QwtRasterData *WaterfallData::copy() const { +#if QWT_VERSION < 0x060000 WaterfallData* returnData = new WaterfallData(boundingRect().left(), boundingRect().right(), _fftPoints, _historyLength); +#else + WaterfallData* returnData = new WaterfallData(interval(Qt::XAxis).minValue(), + interval(Qt::XAxis).maxValue(), + _fftPoints, _historyLength); +#endif + returnData->Copy(this); return returnData; } + +#if QWT_VERSION < 0x060000 QwtDoubleInterval WaterfallData::range() const { return _intensityRange; @@ -84,14 +136,27 @@ void WaterfallData::setRange(const QwtDoubleInterval& newRange) _intensityRange = newRange; } +#endif + + double WaterfallData::value(double x, double y) const { double returnValue = 0.0; - + +#if QWT_VERSION < 0x060000 const unsigned int intY = static_cast<unsigned int>((1.0 - (y/boundingRect().height())) * - static_cast<double>(_historyLength - 1)); + static_cast<double>(_historyLength-1)); const unsigned int intX = static_cast<unsigned int>((((x - boundingRect().left()) / boundingRect().width()) * static_cast<double>(_fftPoints-1)) + 0.5); +#else + double height = interval(Qt::YAxis).maxValue(); + double left = interval(Qt::XAxis).minValue(); + double right = interval(Qt::XAxis).maxValue(); + double ylen = static_cast<double>(_historyLength-1); + double xlen = static_cast<double>(_fftPoints-1); + const unsigned int intY = static_cast<unsigned int>((1.0 - y/height) * ylen); + const unsigned int intX = static_cast<unsigned int>((((x - left) / (right-left)) * xlen) + 0.5); +#endif const int location = (intY * _fftPoints) + intX; if((location > -1) && (location < static_cast<int64_t>(_fftPoints * _historyLength))){ @@ -132,7 +197,8 @@ void WaterfallData::addFFTData(const double* fftData, } // add the new buffer - memcpy(&_spectrumData[(_historyLength - 1) * _fftPoints], fftData, _fftPoints*sizeof(double)); + memcpy(&_spectrumData[(_historyLength - 1) * _fftPoints], fftData, + _fftPoints*sizeof(double)); } } diff --git a/gr-qtgui/lib/waterfallGlobalData.h b/gr-qtgui/lib/waterfallGlobalData.h index 51f65064c..89e48da5f 100644 --- a/gr-qtgui/lib/waterfallGlobalData.h +++ b/gr-qtgui/lib/waterfallGlobalData.h @@ -4,6 +4,10 @@ #include <qwt_raster_data.h> #include <inttypes.h> +#if QWT_VERSION >= 0x060000 +#include <qwt_point_3d.h> // doesn't seem necessary, but is... +#include <qwt_compat.h> +#endif class WaterfallData: public QwtRasterData { @@ -17,8 +21,11 @@ public: virtual void ResizeData(const double, const double, const uint64_t); virtual QwtRasterData *copy() const; + +#if QWT_VERSION < 0x060000 virtual QwtDoubleInterval range() const; virtual void setRange(const QwtDoubleInterval&); +#endif virtual double value(double x, double y) const; @@ -38,7 +45,12 @@ protected: uint64_t _fftPoints; uint64_t _historyLength; int _numLinesToUpdate; + +#if QWT_VERSION < 0x060000 QwtDoubleInterval _intensityRange; +#else + QwtInterval _intensityRange; +#endif private: diff --git a/gr-qtgui/python/__init__.py b/gr-qtgui/python/__init__.py index db113bbd3..236f211b1 100644 --- a/gr-qtgui/python/__init__.py +++ b/gr-qtgui/python/__init__.py @@ -19,6 +19,11 @@ # Boston, MA 02110-1301, USA. # +''' +This is the gr-qtgui package. This package includes QT-based graphical +sinks. +''' + # The presence of this file turns this directory into a Python package from qtgui_swig import * diff --git a/gr-qtgui/swig/Makefile.am b/gr-qtgui/swig/Makefile.am index 1d8319987..ad6f49e00 100644 --- a/gr-qtgui/swig/Makefile.am +++ b/gr-qtgui/swig/Makefile.am @@ -31,6 +31,7 @@ AM_CPPFLAGS = \ $(STD_DEFINES_AND_INCLUDES) \ $(PYTHON_CPPFLAGS) \ $(QT_INCLUDES) \ + $(GR_QTGUI_INCLUDES) \ $(WITH_INCLUDES) ############################## diff --git a/gr-qtgui/swig/qtgui_sink_f.i b/gr-qtgui/swig/qtgui_sink_f.i index c5eb656b9..a34420461 100644 --- a/gr-qtgui/swig/qtgui_sink_f.i +++ b/gr-qtgui/swig/qtgui_sink_f.i @@ -32,7 +32,7 @@ qtgui_sink_f_sptr qtgui_make_sink_f (int fftsize, int wintype, double fc=0, double bw=0.0, const std::string &name="Display", bool plotfreq=true, bool plotwaterfall=true, - bool plottime=true, bool plotconst=true, + bool plottime=true, bool plotconst=false, QWidget *parent=NULL); class qtgui_sink_f : public gr_block |