summaryrefslogtreecommitdiff
path: root/gr-qtgui/lib/DisplayPlot.cc
diff options
context:
space:
mode:
authorTom Rondeau <trondeau@vt.edu>2012-06-29 08:05:16 -0400
committerTom Rondeau <trondeau@vt.edu>2012-06-29 08:05:16 -0400
commit68e4c1b8b58126ea8676540b2c7b0bdf2e36fd9e (patch)
tree226382e50d3b5deab771c1e02535557e06bfbcda /gr-qtgui/lib/DisplayPlot.cc
parentbc77a2f13c4517459f4759bd2d95c7744282264a (diff)
qtgui: made display form and display plot base classes to handle duplicated functions.
Forms and plots for each type of graph inherit from here now to make things cleaner.
Diffstat (limited to 'gr-qtgui/lib/DisplayPlot.cc')
-rw-r--r--gr-qtgui/lib/DisplayPlot.cc196
1 files changed, 196 insertions, 0 deletions
diff --git a/gr-qtgui/lib/DisplayPlot.cc b/gr-qtgui/lib/DisplayPlot.cc
new file mode 100644
index 0000000000..031285c8b2
--- /dev/null
+++ b/gr-qtgui/lib/DisplayPlot.cc
@@ -0,0 +1,196 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 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 <DisplayPlot.h>
+
+#include <qwt_scale_draw.h>
+#include <qwt_legend.h>
+#include <QColor>
+#include <cmath>
+#include <iostream>
+
+DisplayPlot::DisplayPlot(int nplots, QWidget* parent)
+ : QwtPlot(parent), _nplots(nplots), _stop(false)
+{
+ resize(parent->width(), parent->height());
+
+ // 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"));
+ canvas()->setPalette(palette);
+
+ _panner = new QwtPlotPanner(canvas());
+ _panner->setAxisEnabled(QwtPlot::yRight, false);
+ _panner->setMouseButton(Qt::MidButton);
+
+ // 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
+ _picker->setStateMachine(new QwtPickerDblClickPointMachine());
+ connect(_picker, SIGNAL(selected(const QPointF &)),
+ this, SLOT(OnPickerPointSelected6(const QPointF &)));
+#endif
+
+ // Configure magnify on mouse wheel
+ _magnifier = new QwtPlotMagnifier(canvas());
+ _magnifier->setAxisEnabled(QwtPlot::xBottom, false);
+
+ // Avoid jumping when labels with more/less digits
+ // appear/disappear when scrolling vertically
+
+ const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font());
+ QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft);
+ sd->setMinimumExtent( fm.width("100.00") );
+
+ QwtLegend* legendDisplay = new QwtLegend(this);
+ legendDisplay->setItemMode(QwtLegend::CheckableItem);
+ insertLegend(legendDisplay);
+
+ connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
+ this, SLOT(LegendEntryChecked(QwtPlotItem *, bool)));
+}
+
+DisplayPlot::~DisplayPlot()
+{
+ // _zoomer and _panner deleted when parent deleted
+}
+
+void
+DisplayPlot::setYaxis(double min, double max)
+{
+ setAxisScale(QwtPlot::yLeft, min, max);
+ _zoomer->setZoomBase();
+}
+
+void
+DisplayPlot::setXaxis(double min, double max)
+{
+ setAxisScale(QwtPlot::xBottom, min, max);
+ _zoomer->setZoomBase();
+}
+
+void
+DisplayPlot::setTitle(int which, QString title)
+{
+ _plot_curve[which]->setTitle(title);
+}
+
+QString
+DisplayPlot::title(int which)
+{
+ return _plot_curve[which]->title().text();
+}
+
+void
+DisplayPlot::setColor(int which, QString color)
+{
+ // Set the color of the pen
+ QPen pen(_plot_curve[which]->pen());
+ pen.setColor(color);
+ _plot_curve[which]->setPen(pen);
+
+ // And set the color of the markers
+ QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
+ sym->setColor(color);
+ _plot_curve[which]->setSymbol(sym);
+}
+
+void
+DisplayPlot::setLineWidth(int which, int width)
+{
+ // Set the new line width
+ QPen pen(_plot_curve[which]->pen());
+ pen.setWidth(width);
+ _plot_curve[which]->setPen(pen);
+
+ // Scale the marker size proportionally
+ QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
+ sym->setSize(7+10*log10(width), 7+10*log10(width));
+ _plot_curve[which]->setSymbol(sym);
+}
+
+void
+DisplayPlot::setLineStyle(int which, Qt::PenStyle style)
+{
+ QPen pen(_plot_curve[which]->pen());
+ pen.setStyle(style);
+ _plot_curve[which]->setPen(pen);
+}
+
+void
+DisplayPlot::setLineMarker(int which, QwtSymbol::Style marker)
+{
+ QwtSymbol *sym = (QwtSymbol*)_plot_curve[which]->symbol();
+ sym->setStyle(marker);
+ _plot_curve[which]->setSymbol(sym);
+}
+
+void
+DisplayPlot::setStop(bool on)
+{
+ _stop = on;
+}
+
+void
+DisplayPlot::resizeSlot( QSize *s )
+{
+ // -10 is to spare some room for the legend and x-axis label
+ resize(s->width()-10, s->height()-10);
+}
+
+void DisplayPlot::LegendEntryChecked(QwtPlotItem* plotItem, bool on)
+{
+ plotItem->setVisible(!on);
+ replot();
+}
+
+void
+DisplayPlot::OnPickerPointSelected(const QwtDoublePoint & p)
+{
+ QPointF point = p;
+ //fprintf(stderr,"OnPickerPointSelected %f %f\n", point.x(), point.y());
+ emit plotPointSelected(point);
+}
+
+void
+DisplayPlot::OnPickerPointSelected6(const QPointF & p)
+{
+ QPointF point = p;
+ //fprintf(stderr,"OnPickerPointSelected %f %f\n", point.x(), point.y());
+ emit plotPointSelected(point);
+}