Released version 6.1.3
This commit is contained in:
commit
a94503cb82
1885 changed files with 276310 additions and 0 deletions
73
examples/refreshtest/circularbuffer.cpp
Normal file
73
examples/refreshtest/circularbuffer.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include "circularbuffer.h"
|
||||
#include <math.h>
|
||||
|
||||
CircularBuffer::CircularBuffer( double interval, size_t numPoints ):
|
||||
d_y( NULL ),
|
||||
d_referenceTime( 0.0 ),
|
||||
d_startIndex( 0 ),
|
||||
d_offset( 0.0 )
|
||||
{
|
||||
fill( interval, numPoints );
|
||||
}
|
||||
|
||||
void CircularBuffer::fill( double interval, size_t numPoints )
|
||||
{
|
||||
if ( interval <= 0.0 || numPoints < 2 )
|
||||
return;
|
||||
|
||||
d_values.resize( numPoints );
|
||||
d_values.fill( 0.0 );
|
||||
|
||||
if ( d_y )
|
||||
{
|
||||
d_step = interval / ( numPoints - 2 );
|
||||
for ( size_t i = 0; i < numPoints; i++ )
|
||||
d_values[i] = d_y( i * d_step );
|
||||
}
|
||||
|
||||
d_interval = interval;
|
||||
}
|
||||
|
||||
void CircularBuffer::setFunction( double( *y )( double ) )
|
||||
{
|
||||
d_y = y;
|
||||
}
|
||||
|
||||
void CircularBuffer::setReferenceTime( double timeStamp )
|
||||
{
|
||||
d_referenceTime = timeStamp;
|
||||
|
||||
const double startTime = ::fmod( d_referenceTime, d_values.size() * d_step );
|
||||
|
||||
d_startIndex = int( startTime / d_step ); // floor
|
||||
d_offset = ::fmod( startTime, d_step );
|
||||
}
|
||||
|
||||
double CircularBuffer::referenceTime() const
|
||||
{
|
||||
return d_referenceTime;
|
||||
}
|
||||
|
||||
size_t CircularBuffer::size() const
|
||||
{
|
||||
return d_values.size();
|
||||
}
|
||||
|
||||
QPointF CircularBuffer::sample( size_t i ) const
|
||||
{
|
||||
const int size = d_values.size();
|
||||
|
||||
int index = d_startIndex + i;
|
||||
if ( index >= size )
|
||||
index -= size;
|
||||
|
||||
const double x = i * d_step - d_offset - d_interval;
|
||||
const double y = d_values.data()[index];
|
||||
|
||||
return QPointF( x, y );
|
||||
}
|
||||
|
||||
QRectF CircularBuffer::boundingRect() const
|
||||
{
|
||||
return QRectF( -1.0, -d_interval, 2.0, d_interval );
|
||||
}
|
35
examples/refreshtest/circularbuffer.h
Normal file
35
examples/refreshtest/circularbuffer.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef _CIRCULAR_BUFFER_H_
|
||||
#define _CIRCULAR_BUFFER_H_
|
||||
|
||||
#include <qwt_series_data.h>
|
||||
#include <qvector.h>
|
||||
|
||||
class CircularBuffer: public QwtSeriesData<QPointF>
|
||||
{
|
||||
public:
|
||||
CircularBuffer( double interval = 10.0, size_t numPoints = 1000 );
|
||||
void fill( double interval, size_t numPoints );
|
||||
|
||||
void setReferenceTime( double );
|
||||
double referenceTime() const;
|
||||
|
||||
virtual size_t size() const;
|
||||
virtual QPointF sample( size_t i ) const;
|
||||
|
||||
virtual QRectF boundingRect() const;
|
||||
|
||||
void setFunction( double( *y )( double ) );
|
||||
|
||||
private:
|
||||
double ( *d_y )( double );
|
||||
|
||||
double d_referenceTime;
|
||||
double d_interval;
|
||||
QVector<double> d_values;
|
||||
|
||||
double d_step;
|
||||
int d_startIndex;
|
||||
double d_offset;
|
||||
};
|
||||
|
||||
#endif
|
30
examples/refreshtest/main.cpp
Normal file
30
examples/refreshtest/main.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include "mainwindow.h"
|
||||
#include <qapplication.h>
|
||||
|
||||
#ifndef QWT_NO_OPENGL
|
||||
#if QT_VERSION >= 0x040600 && QT_VERSION < 0x050000
|
||||
#define USE_OPENGL 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_OPENGL
|
||||
#include <qgl.h>
|
||||
#endif
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
#if USE_OPENGL
|
||||
// on my box QPaintEngine::OpenGL2 has serious problems, f.e:
|
||||
// the lines of a simple drawRect are wrong.
|
||||
|
||||
QGL::setPreferredPaintEngine( QPaintEngine::OpenGL );
|
||||
#endif
|
||||
|
||||
QApplication a( argc, argv );
|
||||
|
||||
MainWindow mainWindow;
|
||||
mainWindow.resize( 600, 400 );
|
||||
mainWindow.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
76
examples/refreshtest/mainwindow.cpp
Normal file
76
examples/refreshtest/mainwindow.cpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include <qstatusbar.h>
|
||||
#include <qlabel.h>
|
||||
#include <qlayout.h>
|
||||
#include <qevent.h>
|
||||
#include <qdatetime.h>
|
||||
#include <qwt_plot_canvas.h>
|
||||
#include "panel.h"
|
||||
#include "plot.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow( QWidget *parent ):
|
||||
QMainWindow( parent )
|
||||
{
|
||||
QWidget *w = new QWidget( this );
|
||||
|
||||
d_panel = new Panel( w );
|
||||
|
||||
d_plot = new Plot( w );
|
||||
|
||||
QHBoxLayout *hLayout = new QHBoxLayout( w );
|
||||
hLayout->addWidget( d_panel );
|
||||
hLayout->addWidget( d_plot, 10 );
|
||||
|
||||
setCentralWidget( w );
|
||||
|
||||
d_frameCount = new QLabel( this );
|
||||
statusBar()->addWidget( d_frameCount, 10 );
|
||||
|
||||
applySettings( d_panel->settings() );
|
||||
|
||||
connect( d_panel, SIGNAL( settingsChanged( const Settings & ) ),
|
||||
this, SLOT( applySettings( const Settings & ) ) );
|
||||
}
|
||||
|
||||
bool MainWindow::eventFilter( QObject *object, QEvent *event )
|
||||
{
|
||||
if ( object == d_plot->canvas() && event->type() == QEvent::Paint )
|
||||
{
|
||||
static int counter;
|
||||
static QTime timeStamp;
|
||||
|
||||
if ( !timeStamp.isValid() )
|
||||
{
|
||||
timeStamp.start();
|
||||
counter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter++;
|
||||
|
||||
const double elapsed = timeStamp.elapsed() / 1000.0;
|
||||
if ( elapsed >= 1 )
|
||||
{
|
||||
QString fps;
|
||||
fps.setNum( qRound( counter / elapsed ) );
|
||||
fps += " Fps";
|
||||
|
||||
d_frameCount->setText( fps );
|
||||
|
||||
counter = 0;
|
||||
timeStamp.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QMainWindow::eventFilter( object, event );
|
||||
}
|
||||
|
||||
void MainWindow::applySettings( const Settings &settings )
|
||||
{
|
||||
d_plot->setSettings( settings );
|
||||
|
||||
// the canvas might have been recreated
|
||||
d_plot->canvas()->removeEventFilter( this );
|
||||
d_plot->canvas()->installEventFilter( this );
|
||||
}
|
28
examples/refreshtest/mainwindow.h
Normal file
28
examples/refreshtest/mainwindow.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef _MAIN_WINDOW_H_
|
||||
#define _MAIN_WINDOW_H_
|
||||
|
||||
#include <qmainwindow.h>
|
||||
|
||||
class Plot;
|
||||
class Panel;
|
||||
class QLabel;
|
||||
class Settings;
|
||||
|
||||
class MainWindow: public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow( QWidget *parent = NULL );
|
||||
virtual bool eventFilter( QObject *, QEvent * );
|
||||
|
||||
private Q_SLOTS:
|
||||
void applySettings( const Settings & );
|
||||
|
||||
private:
|
||||
Plot *d_plot;
|
||||
Panel *d_panel;
|
||||
QLabel *d_frameCount;
|
||||
};
|
||||
|
||||
#endif
|
297
examples/refreshtest/panel.cpp
Normal file
297
examples/refreshtest/panel.cpp
Normal file
|
@ -0,0 +1,297 @@
|
|||
#include "panel.h"
|
||||
#include <qlabel.h>
|
||||
#include <qcombobox.h>
|
||||
#include <qspinbox.h>
|
||||
#include <qcheckbox.h>
|
||||
#include <qlayout.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
|
||||
class SpinBox: public QSpinBox
|
||||
{
|
||||
public:
|
||||
SpinBox( int min, int max, int step, QWidget *parent ):
|
||||
QSpinBox( parent )
|
||||
{
|
||||
setRange( min, max );
|
||||
setSingleStep( step );
|
||||
}
|
||||
};
|
||||
|
||||
class CheckBox: public QCheckBox
|
||||
{
|
||||
public:
|
||||
CheckBox( const QString &title, QWidget *parent ):
|
||||
QCheckBox( title, parent )
|
||||
{
|
||||
}
|
||||
|
||||
void setChecked( bool checked )
|
||||
{
|
||||
setCheckState( checked ? Qt::Checked : Qt::Unchecked );
|
||||
}
|
||||
|
||||
bool isChecked() const
|
||||
{
|
||||
return checkState() == Qt::Checked;
|
||||
}
|
||||
};
|
||||
|
||||
Panel::Panel( QWidget *parent ):
|
||||
QTabWidget( parent )
|
||||
{
|
||||
setTabPosition( QTabWidget::West );
|
||||
|
||||
addTab( createPlotTab( this ), "Plot" );
|
||||
addTab( createCanvasTab( this ), "Canvas" );
|
||||
addTab( createCurveTab( this ), "Curve" );
|
||||
|
||||
setSettings( Settings() );
|
||||
|
||||
connect( d_numPoints, SIGNAL( valueChanged( int ) ), SLOT( edited() ) );
|
||||
connect( d_updateInterval, SIGNAL( valueChanged( int ) ), SLOT( edited() ) );
|
||||
connect( d_curveWidth, SIGNAL( valueChanged( int ) ), SLOT( edited() ) );
|
||||
|
||||
connect( d_paintCache, SIGNAL( stateChanged( int ) ), SLOT( edited() ) );
|
||||
connect( d_paintOnScreen, SIGNAL( stateChanged( int ) ), SLOT( edited() ) );
|
||||
connect( d_immediatePaint, SIGNAL( stateChanged( int ) ), SLOT( edited() ) );
|
||||
#ifndef QWT_NO_OPENGL
|
||||
connect( d_openGL, SIGNAL( stateChanged( int ) ), SLOT( edited() ) );
|
||||
#endif
|
||||
|
||||
connect( d_curveAntialiasing, SIGNAL( stateChanged( int ) ), SLOT( edited() ) );
|
||||
connect( d_curveClipping, SIGNAL( stateChanged( int ) ), SLOT( edited() ) );
|
||||
connect( d_curveFiltering, SIGNAL( stateChanged( int ) ), SLOT( edited() ) );
|
||||
connect( d_lineSplitting, SIGNAL( stateChanged( int ) ), SLOT( edited() ) );
|
||||
connect( d_curveFilled, SIGNAL( stateChanged( int ) ), SLOT( edited() ) );
|
||||
|
||||
connect( d_updateType, SIGNAL( currentIndexChanged( int ) ), SLOT( edited() ) );
|
||||
connect( d_gridStyle, SIGNAL( currentIndexChanged( int ) ), SLOT( edited() ) );
|
||||
connect( d_curveType, SIGNAL( currentIndexChanged( int ) ), SLOT( edited() ) );
|
||||
connect( d_curvePen, SIGNAL( currentIndexChanged( int ) ), SLOT( edited() ) );
|
||||
}
|
||||
|
||||
QWidget *Panel::createPlotTab( QWidget *parent )
|
||||
{
|
||||
QWidget *page = new QWidget( parent );
|
||||
|
||||
d_updateInterval = new SpinBox( 0, 1000, 10, page );
|
||||
d_numPoints = new SpinBox( 10, 1000000, 1000, page );
|
||||
|
||||
d_updateType = new QComboBox( page );
|
||||
d_updateType->addItem( "Repaint" );
|
||||
d_updateType->addItem( "Replot" );
|
||||
|
||||
int row = 0;
|
||||
|
||||
QGridLayout *layout = new QGridLayout( page );
|
||||
|
||||
layout->addWidget( new QLabel( "Updates", page ), row, 0 );
|
||||
layout->addWidget( d_updateInterval, row, 1 );
|
||||
layout->addWidget( new QLabel( "ms", page ), row++, 2 );
|
||||
|
||||
layout->addWidget( new QLabel( "Points", page ), row, 0 );
|
||||
layout->addWidget( d_numPoints, row++, 1 );
|
||||
|
||||
layout->addWidget( new QLabel( "Update", page ), row, 0 );
|
||||
layout->addWidget( d_updateType, row++, 1 );
|
||||
|
||||
layout->addLayout( new QHBoxLayout(), row++, 0 );
|
||||
|
||||
layout->setColumnStretch( 1, 10 );
|
||||
layout->setRowStretch( row, 10 );
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
QWidget *Panel::createCanvasTab( QWidget *parent )
|
||||
{
|
||||
QWidget *page = new QWidget( parent );
|
||||
|
||||
d_gridStyle = new QComboBox( page );
|
||||
d_gridStyle->addItem( "None" );
|
||||
d_gridStyle->addItem( "Solid" );
|
||||
d_gridStyle->addItem( "Dashes" );
|
||||
|
||||
d_paintCache = new CheckBox( "Paint Cache", page );
|
||||
d_paintOnScreen = new CheckBox( "Paint On Screen", page );
|
||||
d_immediatePaint = new CheckBox( "Immediate Paint", page );
|
||||
#ifndef QWT_NO_OPENGL
|
||||
d_openGL = new CheckBox( "OpenGL", page );
|
||||
#endif
|
||||
|
||||
int row = 0;
|
||||
|
||||
QGridLayout *layout = new QGridLayout( page );
|
||||
layout->addWidget( new QLabel( "Grid", page ), row, 0 );
|
||||
layout->addWidget( d_gridStyle, row++, 1 );
|
||||
|
||||
layout->addWidget( d_paintCache, row++, 0, 1, -1 );
|
||||
layout->addWidget( d_paintOnScreen, row++, 0, 1, -1 );
|
||||
layout->addWidget( d_immediatePaint, row++, 0, 1, -1 );
|
||||
#ifndef QWT_NO_OPENGL
|
||||
layout->addWidget( d_openGL, row++, 0, 1, -1 );
|
||||
#endif
|
||||
|
||||
layout->addLayout( new QHBoxLayout(), row++, 0 );
|
||||
|
||||
layout->setColumnStretch( 1, 10 );
|
||||
layout->setRowStretch( row, 10 );
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
QWidget *Panel::createCurveTab( QWidget *parent )
|
||||
{
|
||||
QWidget *page = new QWidget( parent );
|
||||
|
||||
d_curveType = new QComboBox( page );
|
||||
d_curveType->addItem( "Wave" );
|
||||
d_curveType->addItem( "Noise" );
|
||||
|
||||
d_curveAntialiasing = new CheckBox( "Antialiasing", page );
|
||||
d_curveClipping = new CheckBox( "Clipping", page );
|
||||
d_curveFiltering = new CheckBox( "Filtering", page );
|
||||
d_lineSplitting = new CheckBox( "Split Lines", page );
|
||||
|
||||
d_curveWidth = new SpinBox( 0, 10, 1, page );
|
||||
|
||||
d_curvePen = new QComboBox( page );
|
||||
d_curvePen->addItem( "Solid" );
|
||||
d_curvePen->addItem( "Dotted" );
|
||||
|
||||
d_curveFilled = new CheckBox( "Filled", page );
|
||||
|
||||
int row = 0;
|
||||
|
||||
QGridLayout *layout = new QGridLayout( page );
|
||||
layout->addWidget( new QLabel( "Type", page ), row, 0 );
|
||||
layout->addWidget( d_curveType, row++, 1 );
|
||||
|
||||
layout->addWidget( d_curveAntialiasing, row++, 0, 1, -1 );
|
||||
layout->addWidget( d_curveClipping, row++, 0, 1, -1 );
|
||||
layout->addWidget( d_curveFiltering, row++, 0, 1, -1 );
|
||||
layout->addWidget( d_lineSplitting, row++, 0, 1, -1 );
|
||||
|
||||
layout->addWidget( new QLabel( "Width", page ), row, 0 );
|
||||
layout->addWidget( d_curveWidth, row++, 1 );
|
||||
|
||||
layout->addWidget( new QLabel( "Style", page ), row, 0 );
|
||||
layout->addWidget( d_curvePen, row++, 1 );
|
||||
|
||||
layout->addWidget( d_curveFilled, row++, 0, 1, -1 );
|
||||
|
||||
layout->addLayout( new QHBoxLayout(), row++, 0 );
|
||||
|
||||
layout->setColumnStretch( 1, 10 );
|
||||
layout->setRowStretch( row, 10 );
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
void Panel::edited()
|
||||
{
|
||||
const Settings s = settings();
|
||||
Q_EMIT settingsChanged( s );
|
||||
}
|
||||
|
||||
|
||||
Settings Panel::settings() const
|
||||
{
|
||||
Settings s;
|
||||
|
||||
s.grid.pen = QPen( Qt::black, 0 );
|
||||
|
||||
switch( d_gridStyle->currentIndex() )
|
||||
{
|
||||
case 0:
|
||||
s.grid.pen.setStyle( Qt::NoPen );
|
||||
break;
|
||||
case 2:
|
||||
s.grid.pen.setStyle( Qt::DashLine );
|
||||
break;
|
||||
}
|
||||
|
||||
s.curve.pen.setStyle( d_curvePen->currentIndex() == 0 ?
|
||||
Qt::SolidLine : Qt::DotLine );
|
||||
s.curve.pen.setWidth( d_curveWidth->value() );
|
||||
s.curve.brush.setStyle( ( d_curveFilled->isChecked() ) ?
|
||||
Qt::SolidPattern : Qt::NoBrush );
|
||||
s.curve.numPoints = d_numPoints->value();
|
||||
s.curve.functionType = static_cast<Settings::FunctionType>(
|
||||
d_curveType->currentIndex() );
|
||||
if ( d_curveClipping->isChecked() )
|
||||
s.curve.paintAttributes |= QwtPlotCurve::ClipPolygons;
|
||||
else
|
||||
s.curve.paintAttributes &= ~QwtPlotCurve::ClipPolygons;
|
||||
if ( d_curveFiltering->isChecked() )
|
||||
s.curve.paintAttributes |= QwtPlotCurve::FilterPoints;
|
||||
else
|
||||
s.curve.paintAttributes &= ~QwtPlotCurve::FilterPoints;
|
||||
|
||||
if ( d_curveAntialiasing->isChecked() )
|
||||
s.curve.renderHint |= QwtPlotItem::RenderAntialiased;
|
||||
else
|
||||
s.curve.renderHint &= ~QwtPlotItem::RenderAntialiased;
|
||||
|
||||
s.curve.lineSplitting = ( d_lineSplitting->isChecked() );
|
||||
|
||||
s.canvas.useBackingStore = ( d_paintCache->isChecked() );
|
||||
s.canvas.paintOnScreen = ( d_paintOnScreen->isChecked() );
|
||||
s.canvas.immediatePaint = ( d_immediatePaint->isChecked() );
|
||||
#ifndef QWT_NO_OPENGL
|
||||
s.canvas.openGL = ( d_openGL->isChecked() );
|
||||
#endif
|
||||
|
||||
s.updateInterval = d_updateInterval->value();
|
||||
s.updateType = static_cast<Settings::UpdateType>( d_updateType->currentIndex() );
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void Panel::setSettings( const Settings &s )
|
||||
{
|
||||
d_numPoints->setValue( s.curve.numPoints );
|
||||
d_updateInterval->setValue( s.updateInterval );
|
||||
d_updateType->setCurrentIndex( s.updateType );
|
||||
|
||||
switch( s.grid.pen.style() )
|
||||
{
|
||||
case Qt::NoPen:
|
||||
{
|
||||
d_gridStyle->setCurrentIndex( 0 );
|
||||
break;
|
||||
}
|
||||
case Qt::DashLine:
|
||||
{
|
||||
d_gridStyle->setCurrentIndex( 2 );
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
d_gridStyle->setCurrentIndex( 1 ); // Solid
|
||||
}
|
||||
}
|
||||
|
||||
d_paintCache->setChecked( s.canvas.useBackingStore );
|
||||
d_paintOnScreen->setChecked( s.canvas.paintOnScreen );
|
||||
d_immediatePaint->setChecked( s.canvas.immediatePaint );
|
||||
#ifndef QWT_NO_OPENGL
|
||||
d_openGL->setChecked( s.canvas.openGL );
|
||||
#endif
|
||||
|
||||
d_curveType->setCurrentIndex( s.curve.functionType );
|
||||
d_curveAntialiasing->setChecked(
|
||||
s.curve.renderHint & QwtPlotCurve::RenderAntialiased );
|
||||
|
||||
d_curveClipping->setChecked(
|
||||
s.curve.paintAttributes & QwtPlotCurve::ClipPolygons );
|
||||
d_curveFiltering->setChecked(
|
||||
s.curve.paintAttributes & QwtPlotCurve::FilterPoints );
|
||||
|
||||
d_lineSplitting->setChecked( s.curve.lineSplitting );
|
||||
|
||||
d_curveWidth->setValue( s.curve.pen.width() );
|
||||
d_curvePen->setCurrentIndex(
|
||||
s.curve.pen.style() == Qt::SolidLine ? 0 : 1 );
|
||||
d_curveFilled->setChecked( s.curve.brush.style() != Qt::NoBrush );
|
||||
}
|
54
examples/refreshtest/panel.h
Normal file
54
examples/refreshtest/panel.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef _PANEL_H_
|
||||
#define _PANEL_H_ 1
|
||||
|
||||
#include "settings.h"
|
||||
#include <qtabwidget.h>
|
||||
|
||||
class QComboBox;
|
||||
class SpinBox;
|
||||
class CheckBox;
|
||||
|
||||
class Panel: public QTabWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Panel( QWidget * = NULL );
|
||||
|
||||
Settings settings() const;
|
||||
void setSettings( const Settings & );
|
||||
|
||||
Q_SIGNALS:
|
||||
void settingsChanged( const Settings & );
|
||||
|
||||
private Q_SLOTS:
|
||||
void edited();
|
||||
|
||||
private:
|
||||
QWidget *createPlotTab( QWidget * );
|
||||
QWidget *createCanvasTab( QWidget * );
|
||||
QWidget *createCurveTab( QWidget * );
|
||||
|
||||
SpinBox *d_numPoints;
|
||||
SpinBox *d_updateInterval;
|
||||
QComboBox *d_updateType;
|
||||
|
||||
QComboBox *d_gridStyle;
|
||||
CheckBox *d_paintCache;
|
||||
CheckBox *d_paintOnScreen;
|
||||
CheckBox *d_immediatePaint;
|
||||
#ifndef QWT_NO_OPENGL
|
||||
CheckBox *d_openGL;
|
||||
#endif
|
||||
|
||||
QComboBox *d_curveType;
|
||||
CheckBox *d_curveAntialiasing;
|
||||
CheckBox *d_curveClipping;
|
||||
CheckBox *d_curveFiltering;
|
||||
CheckBox *d_lineSplitting;
|
||||
SpinBox *d_curveWidth;
|
||||
QComboBox *d_curvePen;
|
||||
CheckBox *d_curveFilled;
|
||||
};
|
||||
|
||||
#endif
|
222
examples/refreshtest/plot.cpp
Normal file
222
examples/refreshtest/plot.cpp
Normal file
|
@ -0,0 +1,222 @@
|
|||
#include <qglobal.h>
|
||||
#include <qwt_painter.h>
|
||||
#include <qwt_plot_canvas.h>
|
||||
#include <qwt_plot_grid.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_plot_layout.h>
|
||||
#include <qwt_scale_widget.h>
|
||||
#include <qwt_scale_draw.h>
|
||||
#ifndef QWT_NO_OPENGL
|
||||
#include <qevent.h>
|
||||
#include <qwt_plot_glcanvas.h>
|
||||
#endif
|
||||
#include "plot.h"
|
||||
#include "circularbuffer.h"
|
||||
#include "settings.h"
|
||||
|
||||
static double wave( double x )
|
||||
{
|
||||
const double period = 1.0;
|
||||
const double c = 5.0;
|
||||
|
||||
double v = ::fmod( x, period );
|
||||
|
||||
const double amplitude = qAbs( x - qRound( x / c ) * c ) / ( 0.5 * c );
|
||||
v = amplitude * qSin( v / period * 2 * M_PI );
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
static double noise( double )
|
||||
{
|
||||
return 2.0 * ( qrand() / ( static_cast<double>( RAND_MAX ) + 1 ) ) - 1.0;
|
||||
}
|
||||
|
||||
#ifndef QWT_NO_OPENGL
|
||||
class GLCanvas: public QwtPlotGLCanvas
|
||||
{
|
||||
public:
|
||||
GLCanvas( QwtPlot *parent = NULL ):
|
||||
QwtPlotGLCanvas( parent )
|
||||
{
|
||||
setContentsMargins( 1, 1, 1, 1 );
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void paintEvent( QPaintEvent *event )
|
||||
{
|
||||
QPainter painter( this );
|
||||
painter.setClipRegion( event->region() );
|
||||
|
||||
QwtPlot *plot = qobject_cast< QwtPlot *>( parent() );
|
||||
if ( plot )
|
||||
plot->drawCanvas( &painter );
|
||||
|
||||
painter.setPen( palette().foreground().color() );
|
||||
#if QT_VERSION >= 0x050000
|
||||
painter.drawRect( rect().adjusted( 1, 1, 0, 0 ) );
|
||||
#else
|
||||
painter.drawRect( rect().adjusted( 0, 0, -1, -1 ) );
|
||||
#endif
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
Plot::Plot( QWidget *parent ):
|
||||
QwtPlot( parent ),
|
||||
d_interval( 10.0 ), // seconds
|
||||
d_timerId( -1 )
|
||||
{
|
||||
// Assign a title
|
||||
setTitle( "Testing Refresh Rates" );
|
||||
|
||||
QwtPlotCanvas *canvas = new QwtPlotCanvas();
|
||||
canvas->setFrameStyle( QFrame::Box | QFrame::Plain );
|
||||
canvas->setLineWidth( 1 );
|
||||
canvas->setPalette( Qt::white );
|
||||
|
||||
setCanvas( canvas );
|
||||
|
||||
alignScales();
|
||||
|
||||
// Insert grid
|
||||
d_grid = new QwtPlotGrid();
|
||||
d_grid->attach( this );
|
||||
|
||||
// Insert curve
|
||||
d_curve = new QwtPlotCurve( "Data Moving Right" );
|
||||
d_curve->setPen( Qt::black );
|
||||
d_curve->setData( new CircularBuffer( d_interval, 10 ) );
|
||||
d_curve->attach( this );
|
||||
|
||||
// Axis
|
||||
setAxisTitle( QwtPlot::xBottom, "Seconds" );
|
||||
setAxisScale( QwtPlot::xBottom, -d_interval, 0.0 );
|
||||
|
||||
setAxisTitle( QwtPlot::yLeft, "Values" );
|
||||
setAxisScale( QwtPlot::yLeft, -1.0, 1.0 );
|
||||
|
||||
d_clock.start();
|
||||
|
||||
setSettings( d_settings );
|
||||
}
|
||||
|
||||
//
|
||||
// Set a plain canvas frame and align the scales to it
|
||||
//
|
||||
void Plot::alignScales()
|
||||
{
|
||||
// The code below shows how to align the scales to
|
||||
// the canvas frame, but is also a good example demonstrating
|
||||
// why the spreaded API needs polishing.
|
||||
|
||||
for ( int i = 0; i < QwtPlot::axisCnt; i++ )
|
||||
{
|
||||
QwtScaleWidget *scaleWidget = axisWidget( i );
|
||||
if ( scaleWidget )
|
||||
scaleWidget->setMargin( 0 );
|
||||
|
||||
QwtScaleDraw *scaleDraw = axisScaleDraw( i );
|
||||
if ( scaleDraw )
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Backbone, false );
|
||||
}
|
||||
|
||||
plotLayout()->setAlignCanvasToScales( true );
|
||||
}
|
||||
|
||||
void Plot::setSettings( const Settings &s )
|
||||
{
|
||||
if ( d_timerId >= 0 )
|
||||
killTimer( d_timerId );
|
||||
|
||||
d_timerId = startTimer( s.updateInterval );
|
||||
|
||||
d_grid->setPen( s.grid.pen );
|
||||
d_grid->setVisible( s.grid.pen.style() != Qt::NoPen );
|
||||
|
||||
CircularBuffer *buffer = static_cast<CircularBuffer *>( d_curve->data() );
|
||||
if ( s.curve.numPoints != buffer->size() ||
|
||||
s.curve.functionType != d_settings.curve.functionType )
|
||||
{
|
||||
switch( s.curve.functionType )
|
||||
{
|
||||
case Settings::Wave:
|
||||
buffer->setFunction( wave );
|
||||
break;
|
||||
case Settings::Noise:
|
||||
buffer->setFunction( noise );
|
||||
break;
|
||||
default:
|
||||
buffer->setFunction( NULL );
|
||||
}
|
||||
|
||||
buffer->fill( d_interval, s.curve.numPoints );
|
||||
}
|
||||
|
||||
d_curve->setPen( s.curve.pen );
|
||||
d_curve->setBrush( s.curve.brush );
|
||||
|
||||
d_curve->setPaintAttribute( QwtPlotCurve::ClipPolygons,
|
||||
s.curve.paintAttributes & QwtPlotCurve::ClipPolygons );
|
||||
d_curve->setPaintAttribute( QwtPlotCurve::FilterPoints,
|
||||
s.curve.paintAttributes & QwtPlotCurve::FilterPoints );
|
||||
|
||||
d_curve->setRenderHint( QwtPlotItem::RenderAntialiased,
|
||||
s.curve.renderHint & QwtPlotItem::RenderAntialiased );
|
||||
|
||||
#ifndef QWT_NO_OPENGL
|
||||
if ( s.canvas.openGL )
|
||||
{
|
||||
QwtPlotGLCanvas *plotCanvas = qobject_cast<QwtPlotGLCanvas *>( canvas() );
|
||||
if ( plotCanvas == NULL )
|
||||
{
|
||||
plotCanvas = new GLCanvas();
|
||||
plotCanvas->setPalette( QColor( "khaki" ) );
|
||||
|
||||
setCanvas( plotCanvas );
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
QwtPlotCanvas *plotCanvas = qobject_cast<QwtPlotCanvas *>( canvas() );
|
||||
if ( plotCanvas == NULL )
|
||||
{
|
||||
plotCanvas = new QwtPlotCanvas();
|
||||
plotCanvas->setFrameStyle( QFrame::Box | QFrame::Plain );
|
||||
plotCanvas->setLineWidth( 1 );
|
||||
plotCanvas->setPalette( Qt::white );
|
||||
|
||||
setCanvas( plotCanvas );
|
||||
}
|
||||
|
||||
plotCanvas->setAttribute( Qt::WA_PaintOnScreen, s.canvas.paintOnScreen );
|
||||
|
||||
plotCanvas->setPaintAttribute(
|
||||
QwtPlotCanvas::BackingStore, s.canvas.useBackingStore );
|
||||
plotCanvas->setPaintAttribute(
|
||||
QwtPlotCanvas::ImmediatePaint, s.canvas.immediatePaint );
|
||||
}
|
||||
|
||||
QwtPainter::setPolylineSplitting( s.curve.lineSplitting );
|
||||
|
||||
d_settings = s;
|
||||
}
|
||||
|
||||
void Plot::timerEvent( QTimerEvent * )
|
||||
{
|
||||
CircularBuffer *buffer = static_cast<CircularBuffer *>( d_curve->data() );
|
||||
buffer->setReferenceTime( d_clock.elapsed() / 1000.0 );
|
||||
|
||||
if ( d_settings.updateType == Settings::RepaintCanvas )
|
||||
{
|
||||
// the axes in this example doesn't change. So all we need to do
|
||||
// is to repaint the canvas.
|
||||
|
||||
QMetaObject::invokeMethod( canvas(), "replot", Qt::DirectConnection );
|
||||
}
|
||||
else
|
||||
{
|
||||
replot();
|
||||
}
|
||||
}
|
38
examples/refreshtest/plot.h
Normal file
38
examples/refreshtest/plot.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef _PLOT_H_
|
||||
#define _PLOT_H_ 1
|
||||
|
||||
#include <qwt_plot.h>
|
||||
#include <qwt_system_clock.h>
|
||||
#include "settings.h"
|
||||
|
||||
class QwtPlotGrid;
|
||||
class QwtPlotCurve;
|
||||
|
||||
class Plot: public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Plot( QWidget* = NULL );
|
||||
|
||||
public Q_SLOTS:
|
||||
void setSettings( const Settings & );
|
||||
|
||||
protected:
|
||||
virtual void timerEvent( QTimerEvent *e );
|
||||
|
||||
private:
|
||||
void alignScales();
|
||||
|
||||
QwtPlotGrid *d_grid;
|
||||
QwtPlotCurve *d_curve;
|
||||
|
||||
QwtSystemClock d_clock;
|
||||
double d_interval;
|
||||
|
||||
int d_timerId;
|
||||
|
||||
Settings d_settings;
|
||||
};
|
||||
|
||||
#endif
|
27
examples/refreshtest/refreshtest.pro
Normal file
27
examples/refreshtest/refreshtest.pro
Normal file
|
@ -0,0 +1,27 @@
|
|||
################################################################
|
||||
# Qwt Widget Library
|
||||
# Copyright (C) 1997 Josef Wilgen
|
||||
# Copyright (C) 2002 Uwe Rathmann
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the Qwt License, Version 1.0
|
||||
################################################################
|
||||
|
||||
include( $${PWD}/../examples.pri )
|
||||
|
||||
TARGET = refreshtest
|
||||
|
||||
HEADERS = \
|
||||
settings.h \
|
||||
circularbuffer.h \
|
||||
panel.h \
|
||||
plot.h \
|
||||
mainwindow.h
|
||||
|
||||
SOURCES = \
|
||||
circularbuffer.cpp \
|
||||
panel.cpp \
|
||||
plot.cpp \
|
||||
mainwindow.cpp \
|
||||
main.cpp
|
||||
|
78
examples/refreshtest/settings.h
Normal file
78
examples/refreshtest/settings.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
#ifndef _SETTINGS_H_
|
||||
#define _SETTINGS_H_
|
||||
|
||||
#include <qpen.h>
|
||||
#include <qbrush.h>
|
||||
|
||||
class Settings
|
||||
{
|
||||
public:
|
||||
enum FunctionType
|
||||
{
|
||||
NoFunction = -1,
|
||||
|
||||
Wave,
|
||||
Noise
|
||||
};
|
||||
|
||||
enum UpdateType
|
||||
{
|
||||
RepaintCanvas,
|
||||
Replot
|
||||
};
|
||||
|
||||
Settings()
|
||||
{
|
||||
grid.pen = Qt::NoPen;
|
||||
grid.pen.setCosmetic( true );
|
||||
|
||||
curve.brush = Qt::NoBrush;
|
||||
curve.numPoints = 1000;
|
||||
curve.functionType = Wave;
|
||||
curve.paintAttributes = 0;
|
||||
curve.renderHint = 0;
|
||||
curve.lineSplitting = true;
|
||||
|
||||
canvas.useBackingStore = false;
|
||||
canvas.paintOnScreen = false;
|
||||
canvas.immediatePaint = true;
|
||||
#ifndef QWT_NO_OPENGL
|
||||
canvas.openGL = false;
|
||||
#endif
|
||||
|
||||
updateType = RepaintCanvas;
|
||||
updateInterval = 20;
|
||||
}
|
||||
|
||||
struct gridSettings
|
||||
{
|
||||
QPen pen;
|
||||
} grid;
|
||||
|
||||
struct curveSettings
|
||||
{
|
||||
QPen pen;
|
||||
QBrush brush;
|
||||
uint numPoints;
|
||||
FunctionType functionType;
|
||||
int paintAttributes;
|
||||
int renderHint;
|
||||
bool lineSplitting;
|
||||
} curve;
|
||||
|
||||
struct canvasSettings
|
||||
{
|
||||
bool useBackingStore;
|
||||
bool paintOnScreen;
|
||||
bool immediatePaint;
|
||||
|
||||
#ifndef QWT_NO_OPENGL
|
||||
bool openGL;
|
||||
#endif
|
||||
} canvas;
|
||||
|
||||
UpdateType updateType;
|
||||
int updateInterval;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue