Add files from zip

This commit is contained in:
2023-10-31 09:22:42 +01:00
parent 6bacdc5f6d
commit 4dae68036f
2788 changed files with 492537 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "CircularBuffer.h"
#include <QwtMath>
CircularBuffer::CircularBuffer( double interval, size_t numPoints )
: m_y( NULL )
, m_referenceTime( 0.0 )
, m_startIndex( 0 )
, m_offset( 0.0 )
{
fill( interval, numPoints );
}
void CircularBuffer::fill( double interval, size_t numPoints )
{
if ( interval <= 0.0 || numPoints < 2 )
return;
m_values.resize( numPoints );
m_values.fill( 0.0 );
if ( m_y )
{
m_step = interval / ( numPoints - 2 );
for ( size_t i = 0; i < numPoints; i++ )
m_values[i] = m_y( i * m_step );
}
m_interval = interval;
}
void CircularBuffer::setFunction( double ( * y )( double ) )
{
m_y = y;
}
void CircularBuffer::setReferenceTime( double timeStamp )
{
m_referenceTime = timeStamp;
const double startTime = std::fmod( m_referenceTime, m_values.size() * m_step );
m_startIndex = int( startTime / m_step ); // floor
m_offset = std::fmod( startTime, m_step );
}
double CircularBuffer::referenceTime() const
{
return m_referenceTime;
}
size_t CircularBuffer::size() const
{
return m_values.size();
}
QPointF CircularBuffer::sample( size_t i ) const
{
const int size = m_values.size();
int index = m_startIndex + i;
if ( index >= size )
index -= size;
const double x = i * m_step - m_offset - m_interval;
const double y = m_values.data()[index];
return QPointF( x, y );
}
QRectF CircularBuffer::boundingRect() const
{
return QRectF( -1.0, -m_interval, 2.0, m_interval );
}

View File

@@ -0,0 +1,37 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include <QwtSeriesData>
#include <QVector>
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 QWT_OVERRIDE;
virtual QPointF sample( size_t index ) const QWT_OVERRIDE;
virtual QRectF boundingRect() const QWT_OVERRIDE;
void setFunction( double ( * y )( double ) );
private:
double ( * m_y )( double );
double m_referenceTime;
double m_interval;
QVector< double > m_values;
double m_step;
int m_startIndex;
double m_offset;
};

View File

@@ -0,0 +1,82 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "MainWindow.h"
#include "Plot.h"
#include "Panel.h"
#include <QStatusBar>
#include <QLabel>
#include <QLayout>
#include <QEvent>
#include <QElapsedTimer>
MainWindow::MainWindow( QWidget* parent )
: QMainWindow( parent )
{
Panel* panel = new Panel();
m_plot = new Plot();
QWidget* w = new QWidget( this );
QHBoxLayout* hLayout = new QHBoxLayout( w );
hLayout->addWidget( panel );
hLayout->addWidget( m_plot, 10 );
setCentralWidget( w );
m_frameCount = new QLabel( this );
statusBar()->addWidget( m_frameCount, 10 );
applySettings( panel->settings() );
connect( panel, SIGNAL(settingsChanged(const Settings&)),
this, SLOT(applySettings(const Settings&)) );
}
bool MainWindow::eventFilter( QObject* object, QEvent* event )
{
if ( object == m_plot->canvas() && event->type() == QEvent::Paint )
{
static int counter;
static QElapsedTimer 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";
m_frameCount->setText( fps );
counter = 0;
timeStamp.start();
}
}
}
return QMainWindow::eventFilter( object, event );
}
void MainWindow::applySettings( const Settings& settings )
{
m_plot->setSettings( settings );
// the canvas might have been recreated
m_plot->canvas()->removeEventFilter( this );
m_plot->canvas()->installEventFilter( this );
}
#include "moc_MainWindow.cpp"

View File

@@ -0,0 +1,29 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include <QwtGlobal>
#include <QMainWindow>
class Plot;
class QLabel;
class Settings;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget* parent = NULL );
virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE;
private Q_SLOTS:
void applySettings( const Settings& );
private:
Plot* m_plot;
QLabel* m_frameCount;
};

View File

@@ -0,0 +1,332 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "Panel.h"
#include <QwtPlotCurve>
#include <QLabel>
#include <QComboBox>
#include <QSpinBox>
#include <QCheckBox>
#include <QLayout>
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( m_numPoints, SIGNAL(valueChanged(int)), SLOT(edited()) );
connect( m_updateInterval, SIGNAL(valueChanged(int)), SLOT(edited()) );
connect( m_curveWidth, SIGNAL(valueChanged(int)), SLOT(edited()) );
connect( m_paintCache, SIGNAL(stateChanged(int)), SLOT(edited()) );
connect( m_paintOnScreen, SIGNAL(stateChanged(int)), SLOT(edited()) );
connect( m_immediatePaint, SIGNAL(stateChanged(int)), SLOT(edited()) );
#ifndef QWT_NO_OPENGL
connect( m_openGL, SIGNAL(stateChanged(int)), SLOT(edited()) );
#endif
connect( m_curveAntialiasing, SIGNAL(stateChanged(int)), SLOT(edited()) );
connect( m_curveClipping, SIGNAL(stateChanged(int)), SLOT(edited()) );
connect( m_curveWeeding, SIGNAL(currentIndexChanged(int)), SLOT(edited()) );
connect( m_lineSplitting, SIGNAL(stateChanged(int)), SLOT(edited()) );
connect( m_curveFilled, SIGNAL(stateChanged(int)), SLOT(edited()) );
connect( m_updateType, SIGNAL(currentIndexChanged(int)), SLOT(edited()) );
connect( m_gridStyle, SIGNAL(currentIndexChanged(int)), SLOT(edited()) );
connect( m_curveType, SIGNAL(currentIndexChanged(int)), SLOT(edited()) );
connect( m_curvePen, SIGNAL(currentIndexChanged(int)), SLOT(edited()) );
}
QWidget* Panel::createPlotTab( QWidget* parent )
{
QWidget* page = new QWidget( parent );
m_updateInterval = new SpinBox( 0, 1000, 10, page );
m_numPoints = new SpinBox( 10, 1000000, 1000, page );
m_updateType = new QComboBox( page );
m_updateType->addItem( "Repaint" );
m_updateType->addItem( "Replot" );
int row = 0;
QGridLayout* layout = new QGridLayout( page );
layout->addWidget( new QLabel( "Updates", page ), row, 0 );
layout->addWidget( m_updateInterval, row, 1 );
layout->addWidget( new QLabel( "ms", page ), row++, 2 );
layout->addWidget( new QLabel( "Points", page ), row, 0 );
layout->addWidget( m_numPoints, row++, 1 );
layout->addWidget( new QLabel( "Update", page ), row, 0 );
layout->addWidget( m_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 );
m_gridStyle = new QComboBox( page );
m_gridStyle->addItem( "None" );
m_gridStyle->addItem( "Solid" );
m_gridStyle->addItem( "Dashes" );
m_paintCache = new CheckBox( "Paint Cache", page );
m_paintOnScreen = new CheckBox( "Paint On Screen", page );
m_immediatePaint = new CheckBox( "Immediate Paint", page );
#ifndef QWT_NO_OPENGL
m_openGL = new CheckBox( "OpenGL", page );
#endif
int row = 0;
QGridLayout* layout = new QGridLayout( page );
layout->addWidget( new QLabel( "Grid", page ), row, 0 );
layout->addWidget( m_gridStyle, row++, 1 );
layout->addWidget( m_paintCache, row++, 0, 1, -1 );
layout->addWidget( m_paintOnScreen, row++, 0, 1, -1 );
layout->addWidget( m_immediatePaint, row++, 0, 1, -1 );
#ifndef QWT_NO_OPENGL
layout->addWidget( m_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 );
m_curveType = new QComboBox( page );
m_curveType->addItem( "Wave" );
m_curveType->addItem( "Noise" );
m_curveAntialiasing = new CheckBox( "Antialiasing", page );
m_curveClipping = new CheckBox( "Clipping", page );
m_lineSplitting = new CheckBox( "Split Lines", page );
m_curveWeeding = new QComboBox( page );
m_curveWeeding->addItem( "None" );
m_curveWeeding->addItem( "Normal" );
m_curveWeeding->addItem( "Aggressive" );
m_curveWidth = new SpinBox( 0, 10, 1, page );
m_curvePen = new QComboBox( page );
m_curvePen->addItem( "Solid" );
m_curvePen->addItem( "Dotted" );
m_curveFilled = new CheckBox( "Filled", page );
int row = 0;
QGridLayout* layout = new QGridLayout( page );
layout->addWidget( new QLabel( "Type", page ), row, 0 );
layout->addWidget( m_curveType, row++, 1 );
layout->addWidget( m_curveAntialiasing, row++, 0, 1, -1 );
layout->addWidget( m_curveClipping, row++, 0, 1, -1 );
layout->addWidget( m_lineSplitting, row++, 0, 1, -1 );
layout->addWidget( new QLabel( "Weeding", page ), row, 0 );
layout->addWidget( m_curveWeeding, row++, 1 );
layout->addWidget( new QLabel( "Width", page ), row, 0 );
layout->addWidget( m_curveWidth, row++, 1 );
layout->addWidget( new QLabel( "Style", page ), row, 0 );
layout->addWidget( m_curvePen, row++, 1 );
layout->addWidget( m_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( m_gridStyle->currentIndex() )
{
case 0:
s.grid.pen.setStyle( Qt::NoPen );
break;
case 2:
s.grid.pen.setStyle( Qt::DashLine );
break;
}
s.curve.pen.setStyle( m_curvePen->currentIndex() == 0 ?
Qt::SolidLine : Qt::DotLine );
s.curve.pen.setWidth( m_curveWidth->value() );
s.curve.brush.setStyle( ( m_curveFilled->isChecked() ) ?
Qt::SolidPattern : Qt::NoBrush );
s.curve.numPoints = m_numPoints->value();
s.curve.functionType = static_cast< Settings::FunctionType >(
m_curveType->currentIndex() );
if ( m_curveClipping->isChecked() )
s.curve.paintAttributes |= QwtPlotCurve::ClipPolygons;
else
s.curve.paintAttributes &= ~QwtPlotCurve::ClipPolygons;
s.curve.paintAttributes &= ~QwtPlotCurve::FilterPoints;
s.curve.paintAttributes &= ~QwtPlotCurve::FilterPointsAggressive;
switch( m_curveWeeding->currentIndex() )
{
case 1:
{
s.curve.paintAttributes |= QwtPlotCurve::FilterPoints;
break;
}
case 2:
{
s.curve.paintAttributes |= QwtPlotCurve::FilterPointsAggressive;
break;
}
}
if ( m_curveAntialiasing->isChecked() )
s.curve.renderHint |= QwtPlotItem::RenderAntialiased;
else
s.curve.renderHint &= ~QwtPlotItem::RenderAntialiased;
s.curve.lineSplitting = ( m_lineSplitting->isChecked() );
s.canvas.useBackingStore = ( m_paintCache->isChecked() );
s.canvas.paintOnScreen = ( m_paintOnScreen->isChecked() );
s.canvas.immediatePaint = ( m_immediatePaint->isChecked() );
#ifndef QWT_NO_OPENGL
s.canvas.openGL = ( m_openGL->isChecked() );
#endif
s.updateInterval = m_updateInterval->value();
s.updateType = static_cast< Settings::UpdateType >( m_updateType->currentIndex() );
return s;
}
void Panel::setSettings( const Settings& s )
{
m_numPoints->setValue( s.curve.numPoints );
m_updateInterval->setValue( s.updateInterval );
m_updateType->setCurrentIndex( s.updateType );
switch( s.grid.pen.style() )
{
case Qt::NoPen:
{
m_gridStyle->setCurrentIndex( 0 );
break;
}
case Qt::DashLine:
{
m_gridStyle->setCurrentIndex( 2 );
break;
}
default:
{
m_gridStyle->setCurrentIndex( 1 ); // Solid
}
}
m_paintCache->setChecked( s.canvas.useBackingStore );
m_paintOnScreen->setChecked( s.canvas.paintOnScreen );
m_immediatePaint->setChecked( s.canvas.immediatePaint );
#ifndef QWT_NO_OPENGL
m_openGL->setChecked( s.canvas.openGL );
#endif
m_curveType->setCurrentIndex( s.curve.functionType );
m_curveAntialiasing->setChecked(
s.curve.renderHint & QwtPlotCurve::RenderAntialiased );
m_curveClipping->setChecked(
s.curve.paintAttributes & QwtPlotCurve::ClipPolygons );
int weedingIndex = 0;
if ( s.curve.paintAttributes & QwtPlotCurve::FilterPointsAggressive )
weedingIndex = 2;
else if ( s.curve.paintAttributes & QwtPlotCurve::FilterPoints )
weedingIndex = 1;
m_curveWeeding->setCurrentIndex( weedingIndex );
m_lineSplitting->setChecked( s.curve.lineSplitting );
m_curveWidth->setValue( s.curve.pen.width() );
m_curvePen->setCurrentIndex(
s.curve.pen.style() == Qt::SolidLine ? 0 : 1 );
m_curveFilled->setChecked( s.curve.brush.style() != Qt::NoBrush );
}
#include "moc_Panel.cpp"

View File

@@ -0,0 +1,56 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include "Settings.h"
#include <QTabWidget>
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* m_numPoints;
SpinBox* m_updateInterval;
QComboBox* m_updateType;
QComboBox* m_gridStyle;
CheckBox* m_paintCache;
CheckBox* m_paintOnScreen;
CheckBox* m_immediatePaint;
#ifndef QWT_NO_OPENGL
CheckBox* m_openGL;
#endif
QComboBox* m_curveType;
CheckBox* m_curveAntialiasing;
CheckBox* m_curveClipping;
QComboBox* m_curveWeeding;
CheckBox* m_lineSplitting;
SpinBox* m_curveWidth;
QComboBox* m_curvePen;
CheckBox* m_curveFilled;
};

View File

@@ -0,0 +1,227 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "Plot.h"
#include "CircularBuffer.h"
#include "Settings.h"
#include <QwtPainter>
#include <QwtPlotCanvas>
#include <QwtPlotGrid>
#include <QwtPlotCurve>
#include <QwtPlotLayout>
#include <QwtScaleWidget>
#include <QwtScaleDraw>
#include <QwtMath>
#ifndef QWT_NO_OPENGL
#if QT_VERSION >= 0x050400
#define USE_OPENGL_WIDGET 1
#endif
#if USE_OPENGL_WIDGET
#include <QwtPlotOpenGLCanvas>
#else
#include <QwtPlotGLCanvas>
#endif
#endif
static double wave( double x )
{
const double period = 1.0;
const double c = 5.0;
double v = std::fmod( x, period );
const double amplitude = qAbs( x - qRound( x / c ) * c ) / ( 0.5 * c );
v = amplitude * std::sin( v / period * 2 * M_PI );
return v;
}
static double noise( double )
{
return 2.0 * ( qwtRand() / ( static_cast< double >( RAND_MAX ) + 1 ) ) - 1.0;
}
Plot::Plot( QWidget* parent )
: QwtPlot( parent )
, m_interval( 10.0 ) // seconds
, m_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
m_grid = new QwtPlotGrid();
m_grid->attach( this );
// Insert curve
m_curve = new QwtPlotCurve( "Data Moving Right" );
m_curve->setPen( Qt::black );
m_curve->setData( new CircularBuffer( m_interval, 10 ) );
m_curve->attach( this );
// Axis
setAxisTitle( QwtAxis::XBottom, "Seconds" );
setAxisScale( QwtAxis::XBottom, -m_interval, 0.0 );
setAxisTitle( QwtAxis::YLeft, "Values" );
setAxisScale( QwtAxis::YLeft, -1.0, 1.0 );
m_elapsedTimer.start();
setSettings( m_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 axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
{
QwtScaleWidget* scaleWidget = axisWidget( axisPos );
if ( scaleWidget )
scaleWidget->setMargin( 0 );
QwtScaleDraw* scaleDraw = axisScaleDraw( axisPos );
if ( scaleDraw )
scaleDraw->enableComponent( QwtAbstractScaleDraw::Backbone, false );
}
plotLayout()->setAlignCanvasToScales( true );
}
void Plot::setSettings( const Settings& s )
{
if ( m_timerId >= 0 )
killTimer( m_timerId );
m_timerId = startTimer( s.updateInterval );
m_grid->setPen( s.grid.pen );
m_grid->setVisible( s.grid.pen.style() != Qt::NoPen );
CircularBuffer* buffer = static_cast< CircularBuffer* >( m_curve->data() );
if ( s.curve.numPoints != buffer->size() ||
s.curve.functionType != m_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( m_interval, s.curve.numPoints );
}
m_curve->setPen( s.curve.pen );
m_curve->setBrush( s.curve.brush );
m_curve->setPaintAttribute( QwtPlotCurve::ClipPolygons,
s.curve.paintAttributes & QwtPlotCurve::ClipPolygons );
m_curve->setPaintAttribute( QwtPlotCurve::FilterPoints,
s.curve.paintAttributes & QwtPlotCurve::FilterPoints );
m_curve->setPaintAttribute( QwtPlotCurve::FilterPointsAggressive,
s.curve.paintAttributes & QwtPlotCurve::FilterPointsAggressive );
m_curve->setRenderHint( QwtPlotItem::RenderAntialiased,
s.curve.renderHint & QwtPlotItem::RenderAntialiased );
#ifndef QWT_NO_OPENGL
if ( s.canvas.openGL )
{
#if USE_OPENGL_WIDGET
QwtPlotOpenGLCanvas* plotCanvas = qobject_cast< QwtPlotOpenGLCanvas* >( canvas() );
if ( plotCanvas == NULL )
{
plotCanvas = new QwtPlotOpenGLCanvas();
plotCanvas->setPalette( QColor( "NavajoWhite" ) );
plotCanvas->setPalette( QColor( "khaki" ) );
plotCanvas->setFrameStyle( QFrame::Box | QFrame::Plain );
plotCanvas->setLineWidth( 1 );
setCanvas( plotCanvas );
}
#else
QwtPlotGLCanvas* plotCanvas = qobject_cast< QwtPlotGLCanvas* >( canvas() );
if ( plotCanvas == NULL )
{
plotCanvas = new QwtPlotGLCanvas();
plotCanvas->setPalette( QColor( "khaki" ) );
plotCanvas->setFrameStyle( QFrame::Box | QFrame::Plain );
plotCanvas->setLineWidth( 1 );
setCanvas( plotCanvas );
}
#endif
}
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 );
m_settings = s;
}
void Plot::timerEvent( QTimerEvent* )
{
CircularBuffer* buffer = static_cast< CircularBuffer* >( m_curve->data() );
buffer->setReferenceTime( m_elapsedTimer.elapsed() / 1000.0 );
if ( m_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();
}
}
#include "moc_Plot.cpp"

View File

@@ -0,0 +1,41 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include "Settings.h"
#include <QwtPlot>
#include <QElapsedTimer>
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* ) QWT_OVERRIDE;
private:
void alignScales();
QwtPlotGrid* m_grid;
QwtPlotCurve* m_curve;
QElapsedTimer m_elapsedTimer;
double m_interval;
int m_timerId;
Settings m_settings;
};

View File

@@ -0,0 +1,80 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include <QPen>
#include <QBrush>
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;
};

View File

@@ -0,0 +1,18 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "MainWindow.h"
#include <QApplication>
int main( int argc, char* argv[] )
{
QApplication app( argc, argv );
MainWindow window;
window.resize( 600, 400 );
window.show();
return app.exec();
}

View File

@@ -0,0 +1,23 @@
######################################################################
# Qwt Examples - Copyright (C) 2002 Uwe Rathmann
# This file may be used under the terms of the 3-clause BSD License
######################################################################
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