#ifndef HISTOGRAMPLOT_HH_
# define HISTOGRAMPLOT_HH_
# include <qwt_plot.h>
# include <qwt_picker.h>
# include <qwt_plot_picker.h>
class HistogramPlot : public QwtPlot
{
Q_OBJECT
public:
HistogramPlot(QWidget* = 0);
private:
void populate();
private Q_SLOTS:
void showItem(QwtPlotItem*, bool on);
void moved(const QPoint& pos);
void selected(const QPointF& pos);
protected:
QwtScaleDiv fixedNumberScaleDiv() const;
QwtPlotPicker* picker_;
};
#endif /* !HISTOGRAMPLOT_HH_ */
#ifndef HISTOGRAMPLOT_HH_
# define HISTOGRAMPLOT_HH_
# include <qwt_plot.h>
# include <qwt_picker.h>
# include <qwt_plot_picker.h>
class HistogramPlot : public QwtPlot
{
Q_OBJECT
public:
HistogramPlot(QWidget* = 0);
private:
void populate();
private Q_SLOTS:
void showItem(QwtPlotItem*, bool on);
void moved(const QPoint& pos);
void selected(const QPointF& pos);
protected:
QwtScaleDiv fixedNumberScaleDiv() const;
QwtPlotPicker* picker_;
};
#endif /* !HISTOGRAMPLOT_HH_ */
To copy to clipboard, switch view to plain text mode
HistogramPlot::HistogramPlot(QWidget* parent)
: QwtPlot(parent)
{
[...]
picker_ = new QwtPlotPicker(this->canvas());
picker_->setStateMachine(new QwtPickerClickPointMachine);
connect(picker_, SIGNAL(moved(const QPoint&)),
SLOT(moved(const QPoint&)));
connect(picker_, SIGNAL(selected(const QPointF&)),
SLOT(selected(const QPointF&)));
}
void HistogramPlot::moved(const QPoint& pos)
{
QString info;
info.sprintf("Freq=%g, Ampl=%g, Phase=%g",
invTransform(QwtPlot::xBottom, pos.x()),
invTransform(QwtPlot::yLeft, pos.y()),
invTransform(QwtPlot::yRight, pos.y())
);
qDebug() << info;
}
void HistogramPlot::selected(const QPointF& pos)
{
QString info;
info.sprintf("Freq=%g, Ampl=%g, Phase=%g",
invTransform(QwtPlot::xBottom, pos.x()),
invTransform(QwtPlot::yLeft, pos.y()),
invTransform(QwtPlot::yRight, pos.y())
);
qDebug() << info;
}
HistogramPlot::HistogramPlot(QWidget* parent)
: QwtPlot(parent)
{
[...]
picker_ = new QwtPlotPicker(this->canvas());
picker_->setStateMachine(new QwtPickerClickPointMachine);
connect(picker_, SIGNAL(moved(const QPoint&)),
SLOT(moved(const QPoint&)));
connect(picker_, SIGNAL(selected(const QPointF&)),
SLOT(selected(const QPointF&)));
}
void HistogramPlot::moved(const QPoint& pos)
{
QString info;
info.sprintf("Freq=%g, Ampl=%g, Phase=%g",
invTransform(QwtPlot::xBottom, pos.x()),
invTransform(QwtPlot::yLeft, pos.y()),
invTransform(QwtPlot::yRight, pos.y())
);
qDebug() << info;
}
void HistogramPlot::selected(const QPointF& pos)
{
QString info;
info.sprintf("Freq=%g, Ampl=%g, Phase=%g",
invTransform(QwtPlot::xBottom, pos.x()),
invTransform(QwtPlot::yLeft, pos.y()),
invTransform(QwtPlot::yRight, pos.y())
);
qDebug() << info;
}
To copy to clipboard, switch view to plain text mode
Bookmarks