#ifndef NEWPLOT_H
#define NEWPLOT_H
#include <cmath>
#include <QtGui/QDialog>
#include "qwt_plot.h"
#include <qwt_plot_curve.h>
#include <QTimer>
#include <qwt_plot_grid.h>
#include <qwt_plot_panner.h>
#include <QString>
{
Q_OBJECT
public:
newplot
(QWidget *parent
= 0):m_curve
(NULL)
{
m_time = 0;
for (int i = 0; i < 1000; i++)
{
m_x[i] = 0;
m_y[i] = 0.0;
}
this->setTitle("Winch 1");
this
->setAxisTitle
(QwtPlot::xBottom,
"Time/seconds");
this
->setAxisTitle
(QwtPlot::yLeft,
"Force [N]");
//this->axisAutoScale(QwtPlot::yLeft);
this->setAutoReplot(true);
timeFrame = 10;
}
void appendData( double x, double y){
memmove(m_y, &m_y[1], 999 * sizeof(double));
memmove(m_x, &m_x[1], 999 * sizeof(double));
m_y[999] = y;
m_x[999] = x;
}
private slots:
void TimeFrame
( const QString &mystring
) {
timeFrame =mystring.toDouble();
}
void draw()
{
if (!m_curve)
{
m_curve
->setPen
(QPen(QColor::fromRgb(255,
0,
0),
3));
m_curve->setRawSamples(m_x, m_y, 1000);
m_curve->attach(this);
}
//this->setAxisScale(QwtPlot::yLeft, -100, 100);
this
->setAxisScale
(QwtPlot::xBottom, m_x
[999]-timeFrame, m_x
[999]);
// auto replots this
->axisAutoScale
(QwtPlot::yLeft);
this->replot();
// Grid
//QwtPlotGrid *grid = new QwtPlotGrid;
//grid->enableXMin(true);
//grid->enableYMin(true);
//grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
//grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
//grid->attach(this);
//QwtPlotPanner* megaPanner = new QwtPlotPanner(this->canvas());
//megaPanner->setMouseButton(Qt::RightButton);
//megaPanner->setAxisEnabled(QwtPlot::xBottom, false);
}
private:
int m_time;
double m_x[1000];
double m_y[1000];
double timeFrame;
};
#endif // NEWPLOT_H
#ifndef NEWPLOT_H
#define NEWPLOT_H
#include <cmath>
#include <QtGui/QDialog>
#include "qwt_plot.h"
#include <qwt_plot_curve.h>
#include <QTimer>
#include <qwt_plot_grid.h>
#include <qwt_plot_panner.h>
#include <QString>
class newplot : public QwtPlot
{
Q_OBJECT
public:
newplot(QWidget *parent = 0):m_curve(NULL)
{
m_time = 0;
for (int i = 0; i < 1000; i++)
{
m_x[i] = 0;
m_y[i] = 0.0;
}
this->setTitle("Winch 1");
this->setAxisTitle(QwtPlot::xBottom, "Time/seconds");
this->setAxisTitle(QwtPlot::yLeft, "Force [N]");
//this->axisAutoScale(QwtPlot::yLeft);
this->setAutoReplot(true);
timeFrame = 10;
}
void appendData( double x, double y){
memmove(m_y, &m_y[1], 999 * sizeof(double));
memmove(m_x, &m_x[1], 999 * sizeof(double));
m_y[999] = y;
m_x[999] = x;
}
private slots:
void TimeFrame( const QString &mystring)
{
timeFrame =mystring.toDouble();
}
void draw()
{
if (!m_curve)
{
m_curve = new QwtPlotCurve();
m_curve->setPen(QPen(QColor::fromRgb(255, 0, 0), 3));
m_curve->setRawSamples(m_x, m_y, 1000);
m_curve->attach(this);
}
//this->setAxisScale(QwtPlot::yLeft, -100, 100);
this->setAxisScale(QwtPlot::xBottom, m_x[999]-timeFrame, m_x[999]); // auto replots
this->axisAutoScale(QwtPlot::yLeft);
this->replot();
// Grid
//QwtPlotGrid *grid = new QwtPlotGrid;
//grid->enableXMin(true);
//grid->enableYMin(true);
//grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
//grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
//grid->attach(this);
//QwtPlotPanner* megaPanner = new QwtPlotPanner(this->canvas());
//megaPanner->setMouseButton(Qt::RightButton);
//megaPanner->setAxisEnabled(QwtPlot::xBottom, false);
}
private:
QwtPlotCurve *m_curve;
int m_time;
double m_x[1000];
double m_y[1000];
double timeFrame;
};
#endif // NEWPLOT_H
To copy to clipboard, switch view to plain text mode
Bookmarks