Released version 6.1.3
This commit is contained in:
commit
a94503cb82
182 changed files with 276310 additions and 0 deletions
19
examples/animation/animation.pro
Normal file
19
examples/animation/animation.pro
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
################################################################
|
||||
# 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 = animation
|
||||
|
||||
HEADERS = \
|
||||
plot.h
|
||||
|
||||
SOURCES = \
|
||||
plot.cpp \
|
||||
main.cpp
|
||||
46
examples/animation/main.cpp
Normal file
46
examples/animation/main.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include <qapplication.h>
|
||||
#include "plot.h"
|
||||
|
||||
#ifndef QWT_NO_OPENGL
|
||||
#define USE_OPENGL 1
|
||||
#endif
|
||||
|
||||
#if USE_OPENGL
|
||||
#include <qgl.h>
|
||||
#include <qwt_plot_glcanvas.h>
|
||||
#else
|
||||
#include <qwt_plot_canvas.h>
|
||||
#endif
|
||||
|
||||
int main ( int argc, char **argv )
|
||||
{
|
||||
#if USE_OPENGL
|
||||
#if QT_VERSION >= 0x040600 && QT_VERSION < 0x050000
|
||||
// on my box QPaintEngine::OpenGL2 has serious problems, f.e:
|
||||
// the lines of a simple drawRect are wrong.
|
||||
|
||||
QGL::setPreferredPaintEngine( QPaintEngine::OpenGL );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
QApplication a( argc, argv );
|
||||
|
||||
Plot plot;
|
||||
|
||||
#if USE_OPENGL
|
||||
QwtPlotGLCanvas *canvas = new QwtPlotGLCanvas();
|
||||
canvas->setFrameStyle( QwtPlotGLCanvas::NoFrame );
|
||||
#else
|
||||
QwtPlotCanvas *canvas = new QwtPlotCanvas();
|
||||
canvas->setFrameStyle( QFrame::NoFrame );
|
||||
canvas->setPaintAttribute( QwtPlotCanvas::BackingStore, false );
|
||||
#endif
|
||||
|
||||
plot.setCanvas( canvas );
|
||||
plot.setCanvasBackground( QColor( 30, 30, 50 ) );
|
||||
|
||||
plot.resize( 400, 400 );
|
||||
plot.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
241
examples/animation/plot.cpp
Normal file
241
examples/animation/plot.cpp
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
#include <qapplication.h>
|
||||
#include <qwt_math.h>
|
||||
#include <qwt_symbol.h>
|
||||
#include <qwt_curve_fitter.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_plot_canvas.h>
|
||||
#include <qwt_plot_layout.h>
|
||||
#include <qevent.h>
|
||||
#include "plot.h"
|
||||
|
||||
class Curve: public QwtPlotCurve
|
||||
{
|
||||
public:
|
||||
void setTransformation( const QTransform &transform )
|
||||
{
|
||||
d_transform = transform;
|
||||
}
|
||||
|
||||
virtual void updateSamples( double phase )
|
||||
{
|
||||
setSamples( d_transform.map( points( phase ) ) );
|
||||
}
|
||||
|
||||
private:
|
||||
virtual QPolygonF points( double phase ) const = 0;
|
||||
|
||||
private:
|
||||
QTransform d_transform;
|
||||
};
|
||||
|
||||
class Curve1: public Curve
|
||||
{
|
||||
public:
|
||||
Curve1()
|
||||
{
|
||||
setPen( QColor( 150, 150, 200 ), 2 );
|
||||
setStyle( QwtPlotCurve::Lines );
|
||||
|
||||
QwtSplineCurveFitter *curveFitter = new QwtSplineCurveFitter();
|
||||
curveFitter->setSplineSize( 150 );
|
||||
setCurveFitter( curveFitter );
|
||||
|
||||
setCurveAttribute( QwtPlotCurve::Fitted, true );
|
||||
|
||||
QwtSymbol *symbol = new QwtSymbol( QwtSymbol::XCross );
|
||||
symbol->setPen( Qt::yellow );
|
||||
symbol->setSize( 7 );
|
||||
|
||||
setSymbol( symbol );
|
||||
|
||||
// somewhere to the left
|
||||
QTransform transform;
|
||||
transform.scale( 1.5, 1.0 );
|
||||
transform.translate( 1.5, 3.0 );
|
||||
|
||||
setTransformation( transform );
|
||||
}
|
||||
|
||||
virtual QPolygonF points( double phase ) const
|
||||
{
|
||||
QPolygonF points;
|
||||
|
||||
const int numSamples = 15;
|
||||
for ( int i = 0; i < numSamples; i++ )
|
||||
{
|
||||
const double v = 6.28 * double( i ) / double( numSamples - 1 );
|
||||
points += QPointF( qSin( v - phase ), v );
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
};
|
||||
|
||||
class Curve2: public Curve
|
||||
{
|
||||
public:
|
||||
Curve2()
|
||||
{
|
||||
setStyle( QwtPlotCurve::Sticks );
|
||||
setPen( QColor( 200, 150, 50 ) );
|
||||
|
||||
setSymbol( new QwtSymbol( QwtSymbol::Ellipse,
|
||||
QColor( Qt::gray ), QColor( Qt::yellow ), QSize( 5, 5 ) ) );
|
||||
}
|
||||
|
||||
private:
|
||||
virtual QPolygonF points( double phase ) const
|
||||
{
|
||||
QPolygonF points;
|
||||
|
||||
const int numSamples = 50;
|
||||
for ( int i = 0; i < numSamples; i++ )
|
||||
{
|
||||
const double v = 10.0 * i / double( numSamples - 1 );
|
||||
points += QPointF( v, qCos( 3.0 * ( v + phase ) ) );
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
};
|
||||
|
||||
class Curve3: public Curve
|
||||
{
|
||||
public:
|
||||
Curve3()
|
||||
{
|
||||
setStyle( QwtPlotCurve::Lines );
|
||||
setPen( QColor( 100, 200, 150 ), 2 );
|
||||
|
||||
QwtSplineCurveFitter* curveFitter = new QwtSplineCurveFitter();
|
||||
curveFitter->setFitMode( QwtSplineCurveFitter::ParametricSpline );
|
||||
curveFitter->setSplineSize( 200 );
|
||||
setCurveFitter( curveFitter );
|
||||
|
||||
setCurveAttribute( QwtPlotCurve::Fitted, true );
|
||||
|
||||
// somewhere in the top right corner
|
||||
QTransform transform;
|
||||
transform.translate( 7.0, 7.5 );
|
||||
transform.scale( 2.0, 2.0 );
|
||||
|
||||
setTransformation( transform );
|
||||
}
|
||||
|
||||
private:
|
||||
virtual QPolygonF points( double phase ) const
|
||||
{
|
||||
QPolygonF points;
|
||||
|
||||
const int numSamples = 9;
|
||||
for ( int i = 0; i < numSamples; i++ )
|
||||
{
|
||||
const double v = i * 2.0 * M_PI / ( numSamples - 1 );
|
||||
points += QPointF( qSin( v - phase ), qCos( 3.0 * ( v + phase ) ) );
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
};
|
||||
|
||||
class Curve4: public Curve
|
||||
{
|
||||
public:
|
||||
Curve4()
|
||||
{
|
||||
setStyle( QwtPlotCurve::Lines );
|
||||
setPen( Qt::red, 2 );
|
||||
|
||||
initSamples();
|
||||
|
||||
// somewhere in the center
|
||||
QTransform transform;
|
||||
transform.translate( 7.0, 3.0 );
|
||||
transform.scale( 1.5, 1.5 );
|
||||
|
||||
setTransformation( transform );
|
||||
}
|
||||
|
||||
private:
|
||||
virtual QPolygonF points( double phase ) const
|
||||
{
|
||||
const double speed = 0.05;
|
||||
|
||||
const double s = speed * qSin( phase );
|
||||
const double c = qSqrt( 1.0 - s * s );
|
||||
|
||||
for ( int i = 0; i < d_points.size(); i++ )
|
||||
{
|
||||
const QPointF p = d_points[i];
|
||||
|
||||
const double u = p.x();
|
||||
const double v = p.y();
|
||||
|
||||
d_points[i].setX( u * c - v * s );
|
||||
d_points[i].setY( v * c + u * s );
|
||||
}
|
||||
|
||||
return d_points;
|
||||
}
|
||||
|
||||
void initSamples()
|
||||
{
|
||||
const int numSamples = 15;
|
||||
|
||||
for ( int i = 0; i < numSamples; i++ )
|
||||
{
|
||||
const double angle = i * ( 2.0 * M_PI / ( numSamples - 1 ) );
|
||||
|
||||
QPointF p( qCos( angle ), qSin( angle ) );
|
||||
if ( i % 2 )
|
||||
p *= 0.4;
|
||||
|
||||
d_points += p;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
mutable QPolygonF d_points;
|
||||
};
|
||||
|
||||
Plot::Plot( QWidget *parent ):
|
||||
QwtPlot( parent)
|
||||
{
|
||||
setAutoReplot( false );
|
||||
|
||||
setTitle( "Animated Curves" );
|
||||
|
||||
// hide all axes
|
||||
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
|
||||
enableAxis( axis, false );
|
||||
|
||||
plotLayout()->setCanvasMargin( 10 );
|
||||
|
||||
d_curves[0] = new Curve1();
|
||||
d_curves[1] = new Curve2();
|
||||
d_curves[2] = new Curve3();
|
||||
d_curves[3] = new Curve4();
|
||||
|
||||
updateCurves();
|
||||
|
||||
for ( int i = 0; i < CurveCount; i++ )
|
||||
d_curves[i]->attach( this );
|
||||
|
||||
d_time.start();
|
||||
( void )startTimer( 40 );
|
||||
}
|
||||
|
||||
void Plot::timerEvent( QTimerEvent * )
|
||||
{
|
||||
updateCurves();
|
||||
replot();
|
||||
}
|
||||
|
||||
void Plot::updateCurves()
|
||||
{
|
||||
const double speed = 2 * M_PI / 25000.0; // a cycle every 25 seconds
|
||||
|
||||
const double phase = d_time.elapsed() * speed;
|
||||
for ( int i = 0; i < CurveCount; i++ )
|
||||
d_curves[i]->updateSamples( phase );
|
||||
}
|
||||
21
examples/animation/plot.h
Normal file
21
examples/animation/plot.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include <qwt_plot.h>
|
||||
#include <qdatetime.h>
|
||||
|
||||
class Curve;
|
||||
|
||||
class Plot: public QwtPlot
|
||||
{
|
||||
public:
|
||||
Plot( QWidget * = NULL);
|
||||
|
||||
protected:
|
||||
virtual void timerEvent( QTimerEvent * );
|
||||
|
||||
private:
|
||||
void updateCurves();
|
||||
|
||||
enum { CurveCount = 4 };
|
||||
Curve *d_curves[CurveCount];
|
||||
|
||||
QTime d_time;
|
||||
};
|
||||
132
examples/barchart/barchart.cpp
Normal file
132
examples/barchart/barchart.cpp
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
#include "barchart.h"
|
||||
#include <qwt_plot_renderer.h>
|
||||
#include <qwt_plot_canvas.h>
|
||||
#include <qwt_plot_multi_barchart.h>
|
||||
#include <qwt_column_symbol.h>
|
||||
#include <qwt_plot_layout.h>
|
||||
#include <qwt_legend.h>
|
||||
#include <qwt_scale_draw.h>
|
||||
|
||||
BarChart::BarChart( QWidget *parent ):
|
||||
QwtPlot( parent )
|
||||
{
|
||||
setAutoFillBackground( true );
|
||||
|
||||
setPalette( Qt::white );
|
||||
canvas()->setPalette( QColor( "LemonChiffon" ) );
|
||||
|
||||
setTitle( "Bar Chart" );
|
||||
|
||||
setAxisTitle( QwtPlot::yLeft, "Whatever" );
|
||||
setAxisTitle( QwtPlot::xBottom, "Whatever" );
|
||||
|
||||
d_barChartItem = new QwtPlotMultiBarChart( "Bar Chart " );
|
||||
d_barChartItem->setLayoutPolicy( QwtPlotMultiBarChart::AutoAdjustSamples );
|
||||
d_barChartItem->setSpacing( 20 );
|
||||
d_barChartItem->setMargin( 3 );
|
||||
|
||||
d_barChartItem->attach( this );
|
||||
|
||||
insertLegend( new QwtLegend() );
|
||||
|
||||
populate();
|
||||
setOrientation( 0 );
|
||||
|
||||
setAutoReplot( true );
|
||||
}
|
||||
|
||||
void BarChart::populate()
|
||||
{
|
||||
static const char *colors[] = { "DarkOrchid", "SteelBlue", "Gold" };
|
||||
|
||||
const int numSamples = 5;
|
||||
const int numBars = sizeof( colors ) / sizeof( colors[0] );
|
||||
|
||||
QList<QwtText> titles;
|
||||
for ( int i = 0; i < numBars; i++ )
|
||||
{
|
||||
QString title("Bar %1");
|
||||
titles += title.arg( i );
|
||||
}
|
||||
d_barChartItem->setBarTitles( titles );
|
||||
d_barChartItem->setLegendIconSize( QSize( 10, 14 ) );
|
||||
|
||||
for ( int i = 0; i < numBars; i++ )
|
||||
{
|
||||
QwtColumnSymbol *symbol = new QwtColumnSymbol( QwtColumnSymbol::Box );
|
||||
symbol->setLineWidth( 2 );
|
||||
symbol->setFrameStyle( QwtColumnSymbol::Raised );
|
||||
symbol->setPalette( QPalette( colors[i] ) );
|
||||
|
||||
d_barChartItem->setSymbol( i, symbol );
|
||||
}
|
||||
|
||||
QVector< QVector<double> > series;
|
||||
for ( int i = 0; i < numSamples; i++ )
|
||||
{
|
||||
QVector<double> values;
|
||||
for ( int j = 0; j < numBars; j++ )
|
||||
values += ( 2 + qrand() % 8 );
|
||||
|
||||
series += values;
|
||||
}
|
||||
|
||||
d_barChartItem->setSamples( series );
|
||||
}
|
||||
|
||||
void BarChart::setMode( int mode )
|
||||
{
|
||||
if ( mode == 0 )
|
||||
{
|
||||
d_barChartItem->setStyle( QwtPlotMultiBarChart::Grouped );
|
||||
}
|
||||
else
|
||||
{
|
||||
d_barChartItem->setStyle( QwtPlotMultiBarChart::Stacked );
|
||||
}
|
||||
}
|
||||
|
||||
void BarChart::setOrientation( int orientation )
|
||||
{
|
||||
QwtPlot::Axis axis1, axis2;
|
||||
|
||||
if ( orientation == 0 )
|
||||
{
|
||||
axis1 = QwtPlot::xBottom;
|
||||
axis2 = QwtPlot::yLeft;
|
||||
|
||||
d_barChartItem->setOrientation( Qt::Vertical );
|
||||
}
|
||||
else
|
||||
{
|
||||
axis1 = QwtPlot::yLeft;
|
||||
axis2 = QwtPlot::xBottom;
|
||||
|
||||
d_barChartItem->setOrientation( Qt::Horizontal );
|
||||
}
|
||||
|
||||
setAxisScale( axis1, 0, d_barChartItem->dataSize() - 1, 1.0 );
|
||||
setAxisAutoScale( axis2 );
|
||||
|
||||
QwtScaleDraw *scaleDraw1 = axisScaleDraw( axis1 );
|
||||
scaleDraw1->enableComponent( QwtScaleDraw::Backbone, false );
|
||||
scaleDraw1->enableComponent( QwtScaleDraw::Ticks, false );
|
||||
|
||||
QwtScaleDraw *scaleDraw2 = axisScaleDraw( axis2 );
|
||||
scaleDraw2->enableComponent( QwtScaleDraw::Backbone, true );
|
||||
scaleDraw2->enableComponent( QwtScaleDraw::Ticks, true );
|
||||
|
||||
plotLayout()->setAlignCanvasToScale( axis1, true );
|
||||
plotLayout()->setAlignCanvasToScale( axis2, false );
|
||||
|
||||
plotLayout()->setCanvasMargin( 0 );
|
||||
updateCanvasMargins();
|
||||
|
||||
replot();
|
||||
}
|
||||
|
||||
void BarChart::exportChart()
|
||||
{
|
||||
QwtPlotRenderer renderer;
|
||||
renderer.exportTo( this, "barchart.pdf" );
|
||||
}
|
||||
25
examples/barchart/barchart.h
Normal file
25
examples/barchart/barchart.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef _BAR_CHART_H_
|
||||
|
||||
#include <qwt_plot.h>
|
||||
|
||||
class QwtPlotMultiBarChart;
|
||||
|
||||
class BarChart: public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BarChart( QWidget * = NULL );
|
||||
|
||||
public Q_SLOTS:
|
||||
void setMode( int );
|
||||
void setOrientation( int );
|
||||
void exportChart();
|
||||
|
||||
private:
|
||||
void populate();
|
||||
|
||||
QwtPlotMultiBarChart *d_barChartItem;
|
||||
};
|
||||
|
||||
#endif
|
||||
19
examples/barchart/barchart.pro
Normal file
19
examples/barchart/barchart.pro
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
################################################################
|
||||
# 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 = barchart
|
||||
|
||||
SOURCES = \
|
||||
barchart.cpp \
|
||||
main.cpp
|
||||
|
||||
HEADERS = \
|
||||
barchart.h
|
||||
64
examples/barchart/main.cpp
Normal file
64
examples/barchart/main.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#include <qapplication.h>
|
||||
#include <qmainwindow.h>
|
||||
#include <qtoolbar.h>
|
||||
#include <qtoolbutton.h>
|
||||
#include <qcombobox.h>
|
||||
#include "barchart.h"
|
||||
|
||||
class MainWindow: public QMainWindow
|
||||
{
|
||||
public:
|
||||
MainWindow( QWidget * = NULL );
|
||||
|
||||
private:
|
||||
BarChart *d_chart;
|
||||
};
|
||||
|
||||
MainWindow::MainWindow( QWidget *parent ):
|
||||
QMainWindow( parent )
|
||||
{
|
||||
d_chart = new BarChart( this );
|
||||
setCentralWidget( d_chart );
|
||||
|
||||
QToolBar *toolBar = new QToolBar( this );
|
||||
|
||||
QComboBox *typeBox = new QComboBox( toolBar );
|
||||
typeBox->addItem( "Grouped" );
|
||||
typeBox->addItem( "Stacked" );
|
||||
typeBox->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
||||
|
||||
QComboBox *orientationBox = new QComboBox( toolBar );
|
||||
orientationBox->addItem( "Vertical" );
|
||||
orientationBox->addItem( "Horizontal" );
|
||||
orientationBox->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
||||
|
||||
QToolButton *btnExport = new QToolButton( toolBar );
|
||||
btnExport->setText( "Export" );
|
||||
btnExport->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
connect( btnExport, SIGNAL( clicked() ), d_chart, SLOT( exportChart() ) );
|
||||
|
||||
toolBar->addWidget( typeBox );
|
||||
toolBar->addWidget( orientationBox );
|
||||
toolBar->addWidget( btnExport );
|
||||
addToolBar( toolBar );
|
||||
|
||||
d_chart->setMode( typeBox->currentIndex() );
|
||||
connect( typeBox, SIGNAL( currentIndexChanged( int ) ),
|
||||
d_chart, SLOT( setMode( int ) ) );
|
||||
|
||||
d_chart->setOrientation( orientationBox->currentIndex() );
|
||||
connect( orientationBox, SIGNAL( currentIndexChanged( int ) ),
|
||||
d_chart, SLOT( setOrientation( int ) ) );
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
QApplication a( argc, argv );
|
||||
|
||||
MainWindow mainWindow;
|
||||
|
||||
mainWindow.resize( 600, 400 );
|
||||
mainWindow.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
23
examples/bode/bode.pro
Normal file
23
examples/bode/bode.pro
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
################################################################
|
||||
# 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 = bode
|
||||
|
||||
HEADERS = \
|
||||
mainwindow.h \
|
||||
plot.h \
|
||||
complexnumber.h \
|
||||
pixmaps.h
|
||||
|
||||
SOURCES = \
|
||||
plot.cpp \
|
||||
mainwindow.cpp \
|
||||
main.cpp
|
||||
83
examples/bode/complexnumber.h
Normal file
83
examples/bode/complexnumber.h
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#ifndef _COMPLEX_NUMBER_H_
|
||||
#define _COMPLEX_NUMBER_H_
|
||||
|
||||
#include <math.h>
|
||||
|
||||
class ComplexNumber
|
||||
{
|
||||
public:
|
||||
ComplexNumber() ;
|
||||
ComplexNumber( double r, double i = 0.0 );
|
||||
|
||||
double real() const;
|
||||
double imag() const;
|
||||
|
||||
friend ComplexNumber operator*(
|
||||
const ComplexNumber &, const ComplexNumber & );
|
||||
|
||||
friend ComplexNumber operator+(
|
||||
const ComplexNumber &, const ComplexNumber & );
|
||||
|
||||
friend ComplexNumber operator-(
|
||||
const ComplexNumber &, const ComplexNumber & );
|
||||
friend ComplexNumber operator/(
|
||||
const ComplexNumber &, const ComplexNumber & );
|
||||
|
||||
private:
|
||||
double d_real;
|
||||
double d_imag;
|
||||
};
|
||||
|
||||
inline ComplexNumber::ComplexNumber():
|
||||
d_real( 0.0 ),
|
||||
d_imag( -0.0 )
|
||||
{
|
||||
}
|
||||
|
||||
inline ComplexNumber::ComplexNumber( double re, double im ):
|
||||
d_real( re ),
|
||||
d_imag( im )
|
||||
{
|
||||
}
|
||||
|
||||
inline double ComplexNumber::real() const
|
||||
{
|
||||
return d_real;
|
||||
}
|
||||
|
||||
inline double ComplexNumber::imag() const
|
||||
{
|
||||
return d_imag;
|
||||
}
|
||||
|
||||
inline ComplexNumber operator+(
|
||||
const ComplexNumber &x1, const ComplexNumber &x2 )
|
||||
{
|
||||
return ComplexNumber( x1.d_real + x2.d_real, x1.d_imag + x2.d_imag );
|
||||
}
|
||||
|
||||
inline ComplexNumber operator-(
|
||||
const ComplexNumber &x1, const ComplexNumber &x2 )
|
||||
{
|
||||
return ComplexNumber( x1.d_real - x2.d_real, x1.d_imag - x2.d_imag );
|
||||
}
|
||||
|
||||
inline ComplexNumber operator*(
|
||||
const ComplexNumber &x1, const ComplexNumber &x2 )
|
||||
{
|
||||
return ComplexNumber( x1.d_real * x2.d_real - x1.d_imag * x2.d_imag,
|
||||
x1.d_real * x2.d_imag + x2.d_real * x1.d_imag );
|
||||
}
|
||||
|
||||
inline ComplexNumber operator/(
|
||||
const ComplexNumber &x1, const ComplexNumber &x2 )
|
||||
{
|
||||
double denom = x2.d_real * x2.d_real + x2.d_imag * x2.d_imag;
|
||||
|
||||
return ComplexNumber(
|
||||
( x1.d_real * x2.d_real + x1.d_imag * x2.d_imag ) / denom,
|
||||
( x1.d_imag * x2.d_real - x2.d_imag * x1.d_real ) / denom
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
||||
13
examples/bode/main.cpp
Normal file
13
examples/bode/main.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <qapplication.h>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main ( int argc, char **argv )
|
||||
{
|
||||
QApplication a( argc, argv );
|
||||
|
||||
MainWindow w;
|
||||
w.resize( 540, 400 );
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
231
examples/bode/mainwindow.cpp
Normal file
231
examples/bode/mainwindow.cpp
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
#include <qregexp.h>
|
||||
#include <qtoolbar.h>
|
||||
#include <qtoolbutton.h>
|
||||
#include <qlabel.h>
|
||||
#include <qlayout.h>
|
||||
#include <qstatusbar.h>
|
||||
#include <qprinter.h>
|
||||
#include <qpicture.h>
|
||||
#include <qpainter.h>
|
||||
#include <qprintdialog.h>
|
||||
#include <qwt_counter.h>
|
||||
#include <qwt_picker_machine.h>
|
||||
#include <qwt_plot_zoomer.h>
|
||||
#include <qwt_plot_panner.h>
|
||||
#include <qwt_plot_renderer.h>
|
||||
#include <qwt_text.h>
|
||||
#include <qwt_math.h>
|
||||
#include "pixmaps.h"
|
||||
#include "plot.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
class Zoomer: public QwtPlotZoomer
|
||||
{
|
||||
public:
|
||||
Zoomer( int xAxis, int yAxis, QWidget *canvas ):
|
||||
QwtPlotZoomer( xAxis, yAxis, canvas )
|
||||
{
|
||||
setTrackerMode( QwtPicker::AlwaysOff );
|
||||
setRubberBand( QwtPicker::NoRubberBand );
|
||||
|
||||
// RightButton: zoom out by 1
|
||||
// Ctrl+RightButton: zoom out to full size
|
||||
|
||||
setMousePattern( QwtEventPattern::MouseSelect2,
|
||||
Qt::RightButton, Qt::ControlModifier );
|
||||
setMousePattern( QwtEventPattern::MouseSelect3,
|
||||
Qt::RightButton );
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
//
|
||||
// bode.cpp -- A demo program featuring QwtPlot and QwtCounter
|
||||
//
|
||||
// This example demonstrates the mapping of different curves
|
||||
// to different axes in a QwtPlot widget. It also shows how to
|
||||
// display the cursor position and how to implement zooming.
|
||||
//
|
||||
//-----------------------------------------------------------------
|
||||
|
||||
MainWindow::MainWindow( QWidget *parent ):
|
||||
QMainWindow( parent )
|
||||
{
|
||||
d_plot = new Plot( this );
|
||||
|
||||
const int margin = 5;
|
||||
d_plot->setContentsMargins( margin, margin, margin, 0 );
|
||||
|
||||
setContextMenuPolicy( Qt::NoContextMenu );
|
||||
|
||||
d_zoomer[0] = new Zoomer( QwtPlot::xBottom, QwtPlot::yLeft,
|
||||
d_plot->canvas() );
|
||||
d_zoomer[0]->setRubberBand( QwtPicker::RectRubberBand );
|
||||
d_zoomer[0]->setRubberBandPen( QColor( Qt::green ) );
|
||||
d_zoomer[0]->setTrackerMode( QwtPicker::ActiveOnly );
|
||||
d_zoomer[0]->setTrackerPen( QColor( Qt::white ) );
|
||||
|
||||
d_zoomer[1] = new Zoomer( QwtPlot::xTop, QwtPlot::yRight,
|
||||
d_plot->canvas() );
|
||||
|
||||
d_panner = new QwtPlotPanner( d_plot->canvas() );
|
||||
d_panner->setMouseButton( Qt::MidButton );
|
||||
|
||||
d_picker = new QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft,
|
||||
QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
|
||||
d_plot->canvas() );
|
||||
d_picker->setStateMachine( new QwtPickerDragPointMachine() );
|
||||
d_picker->setRubberBandPen( QColor( Qt::green ) );
|
||||
d_picker->setRubberBand( QwtPicker::CrossRubberBand );
|
||||
d_picker->setTrackerPen( QColor( Qt::white ) );
|
||||
|
||||
setCentralWidget( d_plot );
|
||||
|
||||
QToolBar *toolBar = new QToolBar( this );
|
||||
|
||||
QToolButton *btnZoom = new QToolButton( toolBar );
|
||||
btnZoom->setText( "Zoom" );
|
||||
btnZoom->setIcon( QPixmap( zoom_xpm ) );
|
||||
btnZoom->setCheckable( true );
|
||||
btnZoom->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
toolBar->addWidget( btnZoom );
|
||||
connect( btnZoom, SIGNAL( toggled( bool ) ), SLOT( enableZoomMode( bool ) ) );
|
||||
|
||||
#ifndef QT_NO_PRINTER
|
||||
QToolButton *btnPrint = new QToolButton( toolBar );
|
||||
btnPrint->setText( "Print" );
|
||||
btnPrint->setIcon( QPixmap( print_xpm ) );
|
||||
btnPrint->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
toolBar->addWidget( btnPrint );
|
||||
connect( btnPrint, SIGNAL( clicked() ), SLOT( print() ) );
|
||||
#endif
|
||||
|
||||
QToolButton *btnExport = new QToolButton( toolBar );
|
||||
btnExport->setText( "Export" );
|
||||
btnExport->setIcon( QPixmap( print_xpm ) );
|
||||
btnExport->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
toolBar->addWidget( btnExport );
|
||||
connect( btnExport, SIGNAL( clicked() ), SLOT( exportDocument() ) );
|
||||
|
||||
toolBar->addSeparator();
|
||||
|
||||
QWidget *hBox = new QWidget( toolBar );
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout( hBox );
|
||||
layout->setSpacing( 0 );
|
||||
layout->addWidget( new QWidget( hBox ), 10 ); // spacer
|
||||
layout->addWidget( new QLabel( "Damping Factor", hBox ), 0 );
|
||||
layout->addSpacing( 10 );
|
||||
|
||||
QwtCounter *cntDamp = new QwtCounter( hBox );
|
||||
cntDamp->setRange( 0.0, 5.0 );
|
||||
cntDamp->setSingleStep( 0.01 );
|
||||
cntDamp->setValue( 0.0 );
|
||||
|
||||
layout->addWidget( cntDamp, 0 );
|
||||
|
||||
( void )toolBar->addWidget( hBox );
|
||||
|
||||
addToolBar( toolBar );
|
||||
#ifndef QT_NO_STATUSBAR
|
||||
( void )statusBar();
|
||||
#endif
|
||||
|
||||
enableZoomMode( false );
|
||||
showInfo();
|
||||
|
||||
connect( cntDamp, SIGNAL( valueChanged( double ) ),
|
||||
d_plot, SLOT( setDamp( double ) ) );
|
||||
|
||||
connect( d_picker, SIGNAL( moved( const QPoint & ) ),
|
||||
SLOT( moved( const QPoint & ) ) );
|
||||
connect( d_picker, SIGNAL( selected( const QPolygon & ) ),
|
||||
SLOT( selected( const QPolygon & ) ) );
|
||||
}
|
||||
|
||||
#ifndef QT_NO_PRINTER
|
||||
|
||||
void MainWindow::print()
|
||||
{
|
||||
QPrinter printer( QPrinter::HighResolution );
|
||||
|
||||
QString docName = d_plot->title().text();
|
||||
if ( !docName.isEmpty() )
|
||||
{
|
||||
docName.replace ( QRegExp ( QString::fromLatin1 ( "\n" ) ), tr ( " -- " ) );
|
||||
printer.setDocName ( docName );
|
||||
}
|
||||
|
||||
printer.setCreator( "Bode example" );
|
||||
printer.setOrientation( QPrinter::Landscape );
|
||||
|
||||
QPrintDialog dialog( &printer );
|
||||
if ( dialog.exec() )
|
||||
{
|
||||
QwtPlotRenderer renderer;
|
||||
|
||||
if ( printer.colorMode() == QPrinter::GrayScale )
|
||||
{
|
||||
renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground );
|
||||
renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground );
|
||||
renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasFrame );
|
||||
renderer.setLayoutFlag( QwtPlotRenderer::FrameWithScales );
|
||||
}
|
||||
|
||||
renderer.renderTo( d_plot, printer );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void MainWindow::exportDocument()
|
||||
{
|
||||
QwtPlotRenderer renderer;
|
||||
renderer.exportTo( d_plot, "bode.pdf" );
|
||||
}
|
||||
|
||||
void MainWindow::enableZoomMode( bool on )
|
||||
{
|
||||
d_panner->setEnabled( on );
|
||||
|
||||
d_zoomer[0]->setEnabled( on );
|
||||
d_zoomer[0]->zoom( 0 );
|
||||
|
||||
d_zoomer[1]->setEnabled( on );
|
||||
d_zoomer[1]->zoom( 0 );
|
||||
|
||||
d_picker->setEnabled( !on );
|
||||
|
||||
showInfo();
|
||||
}
|
||||
|
||||
void MainWindow::showInfo( QString text )
|
||||
{
|
||||
if ( text == QString::null )
|
||||
{
|
||||
if ( d_picker->rubberBand() )
|
||||
text = "Cursor Pos: Press left mouse button in plot region";
|
||||
else
|
||||
text = "Zoom: Press mouse button and drag";
|
||||
}
|
||||
|
||||
#ifndef QT_NO_STATUSBAR
|
||||
statusBar()->showMessage( text );
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::moved( const QPoint &pos )
|
||||
{
|
||||
QString info;
|
||||
info.sprintf( "Freq=%g, Ampl=%g, Phase=%g",
|
||||
d_plot->invTransform( QwtPlot::xBottom, pos.x() ),
|
||||
d_plot->invTransform( QwtPlot::yLeft, pos.y() ),
|
||||
d_plot->invTransform( QwtPlot::yRight, pos.y() )
|
||||
);
|
||||
showInfo( info );
|
||||
}
|
||||
|
||||
void MainWindow::selected( const QPolygon & )
|
||||
{
|
||||
showInfo();
|
||||
}
|
||||
35
examples/bode/mainwindow.h
Normal file
35
examples/bode/mainwindow.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <qmainwindow.h>
|
||||
|
||||
class QwtPlotZoomer;
|
||||
class QwtPlotPicker;
|
||||
class QwtPlotPanner;
|
||||
class Plot;
|
||||
class QPolygon;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow( QWidget *parent = 0 );
|
||||
|
||||
private Q_SLOTS:
|
||||
void moved( const QPoint & );
|
||||
void selected( const QPolygon & );
|
||||
|
||||
#ifndef QT_NO_PRINTER
|
||||
void print();
|
||||
#endif
|
||||
|
||||
void exportDocument();
|
||||
void enableZoomMode( bool );
|
||||
|
||||
private:
|
||||
void showInfo( QString text = QString::null );
|
||||
|
||||
Plot *d_plot;
|
||||
|
||||
QwtPlotZoomer *d_zoomer[2];
|
||||
QwtPlotPicker *d_picker;
|
||||
QwtPlotPanner *d_panner;
|
||||
};
|
||||
99
examples/bode/pixmaps.h
Normal file
99
examples/bode/pixmaps.h
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#ifndef PIXMAPS_H
|
||||
#define PIXMAPS_H
|
||||
|
||||
static const char *print_xpm[] =
|
||||
{
|
||||
"32 32 12 1",
|
||||
"a c #ffffff",
|
||||
"h c #ffff00",
|
||||
"c c #ffffff",
|
||||
"f c #dcdcdc",
|
||||
"b c #c0c0c0",
|
||||
"j c #a0a0a4",
|
||||
"e c #808080",
|
||||
"g c #808000",
|
||||
"d c #585858",
|
||||
"i c #00ff00",
|
||||
"# c #000000",
|
||||
". c None",
|
||||
"................................",
|
||||
"................................",
|
||||
"...........###..................",
|
||||
"..........#abb###...............",
|
||||
".........#aabbbbb###............",
|
||||
".........#ddaaabbbbb###.........",
|
||||
"........#ddddddaaabbbbb###......",
|
||||
".......#deffddddddaaabbbbb###...",
|
||||
"......#deaaabbbddddddaaabbbbb###",
|
||||
".....#deaaaaaaabbbddddddaaabbbb#",
|
||||
"....#deaaabbbaaaa#ddedddfggaaad#",
|
||||
"...#deaaaaaaaaaa#ddeeeeafgggfdd#",
|
||||
"..#deaaabbbaaaa#ddeeeeabbbbgfdd#",
|
||||
".#deeefaaaaaaa#ddeeeeabbhhbbadd#",
|
||||
"#aabbbeeefaaa#ddeeeeabbbbbbaddd#",
|
||||
"#bbaaabbbeee#ddeeeeabbiibbadddd#",
|
||||
"#bbbbbaaabbbeeeeeeabbbbbbaddddd#",
|
||||
"#bjbbbbbbaaabbbbeabbbbbbadddddd#",
|
||||
"#bjjjjbbbbbbaaaeabbbbbbaddddddd#",
|
||||
"#bjaaajjjbbbbbbaaabbbbadddddddd#",
|
||||
"#bbbbbaaajjjbbbbbbaaaaddddddddd#",
|
||||
"#bjbbbbbbaaajjjbbbbbbddddddddd#.",
|
||||
"#bjjjjbbbbbbaaajjjbbbdddddddd#..",
|
||||
"#bjaaajjjbbbbbbjaajjbddddddd#...",
|
||||
"#bbbbbaaajjjbbbjbbaabdddddd#....",
|
||||
"###bbbbbbaaajjjjbbbbbddddd#.....",
|
||||
"...###bbbbbbaaajbbbbbdddd#......",
|
||||
"......###bbbbbbjbbbbbddd#.......",
|
||||
".........###bbbbbbbbbdd#........",
|
||||
"............###bbbbbbd#.........",
|
||||
"...............###bbb#..........",
|
||||
"..................###..........."
|
||||
};
|
||||
|
||||
|
||||
static const char *zoom_xpm[] =
|
||||
{
|
||||
"32 32 8 1",
|
||||
"# c #000000",
|
||||
"b c #c0c0c0",
|
||||
"a c #ffffff",
|
||||
"e c #585858",
|
||||
"d c #a0a0a4",
|
||||
"c c #0000ff",
|
||||
"f c #00ffff",
|
||||
". c None",
|
||||
"..######################........",
|
||||
".#a#baaaaaaaaaaaaaaaaaa#........",
|
||||
"#aa#baaaaaaaaaaaaaccaca#........",
|
||||
"####baaaaaaaaaaaaaaaaca####.....",
|
||||
"#bbbbaaaaaaaaaaaacccaaa#da#.....",
|
||||
"#aaaaaaaaaaaaaaaacccaca#da#.....",
|
||||
"#aaaaaaaaaaaaaaaaaccaca#da#.....",
|
||||
"#aaaaaaaaaabe###ebaaaaa#da#.....",
|
||||
"#aaaaaaaaa#########aaaa#da#.....",
|
||||
"#aaaaaaaa###dbbbb###aaa#da#.....",
|
||||
"#aaaaaaa###aaaaffb###aa#da#.....",
|
||||
"#aaaaaab##aaccaaafb##ba#da#.....",
|
||||
"#aaaaaae#daaccaccaad#ea#da#.....",
|
||||
"#aaaaaa##aaaaaaccaab##a#da#.....",
|
||||
"#aaaaaa##aacccaaaaab##a#da#.....",
|
||||
"#aaaaaa##aaccccaccab##a#da#.....",
|
||||
"#aaaaaae#daccccaccad#ea#da#.....",
|
||||
"#aaaaaab##aacccaaaa##da#da#.....",
|
||||
"#aaccacd###aaaaaaa###da#da#.....",
|
||||
"#aaaaacad###daaad#####a#da#.....",
|
||||
"#acccaaaad##########da##da#.....",
|
||||
"#acccacaaadde###edd#eda#da#.....",
|
||||
"#aaccacaaaabdddddbdd#eda#a#.....",
|
||||
"#aaaaaaaaaaaaaaaaaadd#eda##.....",
|
||||
"#aaaaaaaaaaaaaaaaaaadd#eda#.....",
|
||||
"#aaaaaaaccacaaaaaaaaadd#eda#....",
|
||||
"#aaaaaaaaaacaaaaaaaaaad##eda#...",
|
||||
"#aaaaaacccaaaaaaaaaaaaa#d#eda#..",
|
||||
"########################dd#eda#.",
|
||||
"...#dddddddddddddddddddddd##eda#",
|
||||
"...#aaaaaaaaaaaaaaaaaaaaaa#.####",
|
||||
"...########################..##."
|
||||
};
|
||||
|
||||
#endif
|
||||
190
examples/bode/plot.cpp
Normal file
190
examples/bode/plot.cpp
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
#include <qwt_math.h>
|
||||
#include <qwt_scale_engine.h>
|
||||
#include <qwt_symbol.h>
|
||||
#include <qwt_plot_grid.h>
|
||||
#include <qwt_plot_marker.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_legend.h>
|
||||
#include <qwt_text.h>
|
||||
#include <qwt_plot_canvas.h>
|
||||
#include <qmath.h>
|
||||
#include "complexnumber.h"
|
||||
#include "plot.h"
|
||||
|
||||
#if QT_VERSION < 0x040601
|
||||
#define qExp(x) ::exp(x)
|
||||
#define qAtan2(y, x) ::atan2(y, x)
|
||||
#endif
|
||||
|
||||
static void logSpace( double *array, int size, double xmin, double xmax )
|
||||
{
|
||||
if ( ( xmin <= 0.0 ) || ( xmax <= 0.0 ) || ( size <= 0 ) )
|
||||
return;
|
||||
|
||||
const int imax = size - 1;
|
||||
|
||||
array[0] = xmin;
|
||||
array[imax] = xmax;
|
||||
|
||||
const double lxmin = log( xmin );
|
||||
const double lxmax = log( xmax );
|
||||
const double lstep = ( lxmax - lxmin ) / double( imax );
|
||||
|
||||
for ( int i = 1; i < imax; i++ )
|
||||
array[i] = qExp( lxmin + double( i ) * lstep );
|
||||
}
|
||||
|
||||
Plot::Plot( QWidget *parent ):
|
||||
QwtPlot( parent )
|
||||
{
|
||||
setAutoReplot( false );
|
||||
|
||||
setTitle( "Frequency Response of a Second-Order System" );
|
||||
|
||||
QwtPlotCanvas *canvas = new QwtPlotCanvas();
|
||||
canvas->setBorderRadius( 10 );
|
||||
|
||||
setCanvas( canvas );
|
||||
setCanvasBackground( QColor( "MidnightBlue" ) );
|
||||
|
||||
// legend
|
||||
QwtLegend *legend = new QwtLegend;
|
||||
insertLegend( legend, QwtPlot::BottomLegend );
|
||||
|
||||
// grid
|
||||
QwtPlotGrid *grid = new QwtPlotGrid;
|
||||
grid->enableXMin( true );
|
||||
grid->setMajorPen( Qt::white, 0, Qt::DotLine );
|
||||
grid->setMinorPen( Qt::gray, 0 , Qt::DotLine );
|
||||
grid->attach( this );
|
||||
|
||||
// axes
|
||||
enableAxis( QwtPlot::yRight );
|
||||
setAxisTitle( QwtPlot::xBottom, "Normalized Frequency" );
|
||||
setAxisTitle( QwtPlot::yLeft, "Amplitude [dB]" );
|
||||
setAxisTitle( QwtPlot::yRight, "Phase [deg]" );
|
||||
|
||||
setAxisMaxMajor( QwtPlot::xBottom, 6 );
|
||||
setAxisMaxMinor( QwtPlot::xBottom, 9 );
|
||||
setAxisScaleEngine( QwtPlot::xBottom, new QwtLogScaleEngine );
|
||||
|
||||
// curves
|
||||
d_curve1 = new QwtPlotCurve( "Amplitude" );
|
||||
d_curve1->setRenderHint( QwtPlotItem::RenderAntialiased );
|
||||
d_curve1->setPen( Qt::yellow );
|
||||
d_curve1->setLegendAttribute( QwtPlotCurve::LegendShowLine );
|
||||
d_curve1->setYAxis( QwtPlot::yLeft );
|
||||
d_curve1->attach( this );
|
||||
|
||||
d_curve2 = new QwtPlotCurve( "Phase" );
|
||||
d_curve2->setRenderHint( QwtPlotItem::RenderAntialiased );
|
||||
d_curve2->setPen( Qt::cyan );
|
||||
d_curve2->setLegendAttribute( QwtPlotCurve::LegendShowLine );
|
||||
d_curve2->setYAxis( QwtPlot::yRight );
|
||||
d_curve2->attach( this );
|
||||
|
||||
// marker
|
||||
d_marker1 = new QwtPlotMarker();
|
||||
d_marker1->setValue( 0.0, 0.0 );
|
||||
d_marker1->setLineStyle( QwtPlotMarker::VLine );
|
||||
d_marker1->setLabelAlignment( Qt::AlignRight | Qt::AlignBottom );
|
||||
d_marker1->setLinePen( Qt::green, 0, Qt::DashDotLine );
|
||||
d_marker1->attach( this );
|
||||
|
||||
d_marker2 = new QwtPlotMarker();
|
||||
d_marker2->setLineStyle( QwtPlotMarker::HLine );
|
||||
d_marker2->setLabelAlignment( Qt::AlignRight | Qt::AlignBottom );
|
||||
d_marker2->setLinePen( QColor( 200, 150, 0 ), 0, Qt::DashDotLine );
|
||||
d_marker2->setSymbol( new QwtSymbol( QwtSymbol::Diamond,
|
||||
QColor( Qt::yellow ), QColor( Qt::green ), QSize( 8, 8 ) ) );
|
||||
d_marker2->attach( this );
|
||||
|
||||
setDamp( 0.0 );
|
||||
|
||||
setAutoReplot( true );
|
||||
}
|
||||
|
||||
void Plot::showData( const double *frequency, const double *amplitude,
|
||||
const double *phase, int count )
|
||||
{
|
||||
d_curve1->setSamples( frequency, amplitude, count );
|
||||
d_curve2->setSamples( frequency, phase, count );
|
||||
}
|
||||
|
||||
void Plot::showPeak( double freq, double amplitude )
|
||||
{
|
||||
QString label;
|
||||
label.sprintf( "Peak: %.3g dB", amplitude );
|
||||
|
||||
QwtText text( label );
|
||||
text.setFont( QFont( "Helvetica", 10, QFont::Bold ) );
|
||||
text.setColor( QColor( 200, 150, 0 ) );
|
||||
|
||||
d_marker2->setValue( freq, amplitude );
|
||||
d_marker2->setLabel( text );
|
||||
}
|
||||
|
||||
void Plot::show3dB( double freq )
|
||||
{
|
||||
QString label;
|
||||
label.sprintf( "-3 dB at f = %.3g", freq );
|
||||
|
||||
QwtText text( label );
|
||||
text.setFont( QFont( "Helvetica", 10, QFont::Bold ) );
|
||||
text.setColor( Qt::green );
|
||||
|
||||
d_marker1->setValue( freq, 0.0 );
|
||||
d_marker1->setLabel( text );
|
||||
}
|
||||
|
||||
//
|
||||
// re-calculate frequency response
|
||||
//
|
||||
void Plot::setDamp( double damping )
|
||||
{
|
||||
const bool doReplot = autoReplot();
|
||||
setAutoReplot( false );
|
||||
|
||||
const int ArraySize = 200;
|
||||
|
||||
double frequency[ArraySize];
|
||||
double amplitude[ArraySize];
|
||||
double phase[ArraySize];
|
||||
|
||||
// build frequency vector with logarithmic division
|
||||
logSpace( frequency, ArraySize, 0.01, 100 );
|
||||
|
||||
int i3 = 1;
|
||||
double fmax = 1;
|
||||
double amax = -1000.0;
|
||||
|
||||
for ( int i = 0; i < ArraySize; i++ )
|
||||
{
|
||||
double f = frequency[i];
|
||||
const ComplexNumber g =
|
||||
ComplexNumber( 1.0 ) / ComplexNumber( 1.0 - f * f, 2.0 * damping * f );
|
||||
|
||||
amplitude[i] = 20.0 * log10( qSqrt( g.real() * g.real() + g.imag() * g.imag() ) );
|
||||
phase[i] = qAtan2( g.imag(), g.real() ) * ( 180.0 / M_PI );
|
||||
|
||||
if ( ( i3 <= 1 ) && ( amplitude[i] < -3.0 ) )
|
||||
i3 = i;
|
||||
if ( amplitude[i] > amax )
|
||||
{
|
||||
amax = amplitude[i];
|
||||
fmax = frequency[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
double f3 = frequency[i3] - ( frequency[i3] - frequency[i3 - 1] )
|
||||
/ ( amplitude[i3] - amplitude[i3 -1] ) * ( amplitude[i3] + 3 );
|
||||
|
||||
showPeak( fmax, amax );
|
||||
show3dB( f3 );
|
||||
showData( frequency, amplitude, phase, ArraySize );
|
||||
|
||||
setAutoReplot( doReplot );
|
||||
|
||||
replot();
|
||||
}
|
||||
31
examples/bode/plot.h
Normal file
31
examples/bode/plot.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef _PLOT_H_
|
||||
#define _PLOT_H_
|
||||
|
||||
#include <qwt_plot.h>
|
||||
|
||||
class QwtPlotCurve;
|
||||
class QwtPlotMarker;
|
||||
|
||||
class Plot: public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Plot( QWidget *parent );
|
||||
|
||||
public Q_SLOTS:
|
||||
void setDamp( double damping );
|
||||
|
||||
private:
|
||||
void showData( const double *frequency, const double *amplitude,
|
||||
const double *phase, int count );
|
||||
void showPeak( double freq, double amplitude );
|
||||
void show3dB( double freq );
|
||||
|
||||
QwtPlotCurve *d_curve1;
|
||||
QwtPlotCurve *d_curve2;
|
||||
QwtPlotMarker *d_marker1;
|
||||
QwtPlotMarker *d_marker2;
|
||||
};
|
||||
|
||||
#endif
|
||||
34
examples/controls/controls.pro
Normal file
34
examples/controls/controls.pro
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
################################################################
|
||||
# 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 = controls
|
||||
|
||||
HEADERS = \
|
||||
sliderbox.h \
|
||||
slidertab.h \
|
||||
wheelbox.h \
|
||||
wheeltab.h \
|
||||
knobbox.h \
|
||||
knobtab.h \
|
||||
dialbox.h \
|
||||
dialtab.h
|
||||
|
||||
SOURCES = \
|
||||
sliderbox.cpp \
|
||||
slidertab.cpp \
|
||||
wheelbox.cpp \
|
||||
wheeltab.cpp \
|
||||
knobbox.cpp \
|
||||
knobtab.cpp \
|
||||
dialbox.cpp \
|
||||
dialtab.cpp \
|
||||
main.cpp
|
||||
|
||||
163
examples/controls/dialbox.cpp
Normal file
163
examples/controls/dialbox.cpp
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
#include <qlabel.h>
|
||||
#include <qlayout.h>
|
||||
#include <qwt_dial.h>
|
||||
#include <qwt_dial_needle.h>
|
||||
#include <qwt_scale_engine.h>
|
||||
#include <qwt_transform.h>
|
||||
#include <qwt_round_scale_draw.h>
|
||||
#include "dialbox.h"
|
||||
|
||||
DialBox::DialBox( QWidget *parent, int type ):
|
||||
QWidget( parent )
|
||||
{
|
||||
d_dial = createDial( type );
|
||||
|
||||
d_label = new QLabel( this );
|
||||
d_label->setAlignment( Qt::AlignCenter );
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout( this );;
|
||||
layout->setSpacing( 0 );
|
||||
layout->addWidget( d_dial, 10 );
|
||||
layout->addWidget( d_label );
|
||||
|
||||
connect( d_dial, SIGNAL( valueChanged( double ) ),
|
||||
this, SLOT( setNum( double ) ) );
|
||||
|
||||
setNum( d_dial->value() );
|
||||
}
|
||||
|
||||
QwtDial *DialBox::createDial( int type ) const
|
||||
{
|
||||
QwtDial *dial = new QwtDial();
|
||||
dial->setTracking( true );
|
||||
dial->setFocusPolicy( Qt::StrongFocus );
|
||||
dial->setObjectName( QString( "Dial %1" ).arg( type + 1 ) );
|
||||
|
||||
QColor needleColor( Qt::red );
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
dial->setOrigin( 135.0 );
|
||||
dial->setScaleArc( 0.0, 270.0 );
|
||||
dial->setScaleMaxMinor( 4 );
|
||||
dial->setScaleMaxMajor( 10 );
|
||||
dial->setScale( -100.0, 100.0 );
|
||||
|
||||
needleColor = QColor( "Goldenrod" );
|
||||
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
dial->setOrigin( 135.0 );
|
||||
dial->setScaleArc( 0.0, 270.0 );
|
||||
dial->setScaleMaxMinor( 10 );
|
||||
dial->setScaleMaxMajor( 10 );
|
||||
dial->setScale( 10.0, 0.0 );
|
||||
|
||||
QwtRoundScaleDraw *scaleDraw = new QwtRoundScaleDraw();
|
||||
scaleDraw->setSpacing( 8 );
|
||||
scaleDraw->enableComponent(
|
||||
QwtAbstractScaleDraw::Backbone, false );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MinorTick, 2 );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MediumTick, 4 );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MajorTick, 8 );
|
||||
dial->setScaleDraw( scaleDraw );
|
||||
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
dial->setOrigin( 150.0 );
|
||||
dial->setScaleArc( 0.0, 240.0 );
|
||||
|
||||
QwtLinearScaleEngine *scaleEngine = new QwtLinearScaleEngine( 2 );
|
||||
scaleEngine->setTransformation( new QwtPowerTransform( 2 ) );
|
||||
dial->setScaleEngine( scaleEngine );
|
||||
|
||||
QList< double > ticks[ QwtScaleDiv::NTickTypes ];
|
||||
ticks[ QwtScaleDiv::MajorTick ] << 0 << 4
|
||||
<< 16 << 32 << 64 << 96 << 128;
|
||||
ticks[ QwtScaleDiv::MediumTick ] << 24 << 48 << 80 << 112;
|
||||
ticks[ QwtScaleDiv::MinorTick ]
|
||||
<< 0.5 << 1 << 2
|
||||
<< 7 << 10 << 13
|
||||
<< 20 << 28
|
||||
<< 40 << 56
|
||||
<< 72 << 88
|
||||
<< 104 << 120;
|
||||
|
||||
dial->setScale( QwtScaleDiv( 0, 128, ticks ) );
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
dial->setOrigin( 135.0 );
|
||||
dial->setScaleArc( 0.0, 270.0 );
|
||||
dial->setScaleMaxMinor( 9 );
|
||||
dial->setScaleEngine( new QwtLogScaleEngine );
|
||||
dial->setScale( 1.0e-2, 1.0e2 );
|
||||
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
dial->setOrigin( 225.0 );
|
||||
dial->setScaleArc( 0.0, 360.0 );
|
||||
dial->setScaleMaxMinor( 5 );
|
||||
dial->setScaleStepSize( 20 );
|
||||
dial->setScale( 100.0, -100.0 );
|
||||
dial->setWrapping( true );
|
||||
dial->setTotalSteps( 40 );
|
||||
dial->setMode( QwtDial::RotateScale );
|
||||
dial->setValue( 70.0 );
|
||||
|
||||
needleColor = QColor( "DarkSlateBlue" );
|
||||
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
dial->setOrigin( 45.0 );
|
||||
dial->setScaleArc( 0.0, 225.0 );
|
||||
dial->setScaleMaxMinor( 5 );
|
||||
dial->setScaleMaxMajor( 10 );
|
||||
dial->setScale( 0.0, 10.0 );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QwtDialSimpleNeedle *needle = new QwtDialSimpleNeedle(
|
||||
QwtDialSimpleNeedle::Arrow, true, needleColor,
|
||||
QColor( Qt::gray ).light( 130 ) );
|
||||
dial->setNeedle( needle );
|
||||
|
||||
//const QColor base( QColor( "DimGray" ) );
|
||||
const QColor base( QColor( Qt::darkGray ).dark( 150 ) );
|
||||
|
||||
QPalette palette;
|
||||
palette.setColor( QPalette::Base, base );
|
||||
palette.setColor( QPalette::Window, base.dark( 150 ) );
|
||||
palette.setColor( QPalette::Mid, base.dark( 110 ) );
|
||||
palette.setColor( QPalette::Light, base.light( 170 ) );
|
||||
palette.setColor( QPalette::Dark, base.dark( 170 ) );
|
||||
palette.setColor( QPalette::Text, base.dark( 200 ).light( 800 ) );
|
||||
palette.setColor( QPalette::WindowText, base.dark( 200 ) );
|
||||
|
||||
dial->setPalette( palette );
|
||||
dial->setLineWidth( 4 );
|
||||
dial->setFrameShadow( QwtDial::Sunken );
|
||||
|
||||
return dial;
|
||||
}
|
||||
|
||||
void DialBox::setNum( double v )
|
||||
{
|
||||
QString text;
|
||||
text.setNum( v, 'f', 2 );
|
||||
|
||||
d_label->setText( text );
|
||||
}
|
||||
25
examples/controls/dialbox.h
Normal file
25
examples/controls/dialbox.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef _DIAL_BOX_H_
|
||||
#define _DIAL_BOX_H_
|
||||
|
||||
#include <qwidget.h>
|
||||
|
||||
class QLabel;
|
||||
class QwtDial;
|
||||
|
||||
class DialBox: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DialBox( QWidget *parent, int type );
|
||||
|
||||
private Q_SLOTS:
|
||||
void setNum( double v );
|
||||
|
||||
private:
|
||||
QwtDial *createDial( int type ) const;
|
||||
|
||||
QwtDial *d_dial;
|
||||
QLabel *d_label;
|
||||
};
|
||||
|
||||
#endif
|
||||
17
examples/controls/dialtab.cpp
Normal file
17
examples/controls/dialtab.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include "dialtab.h"
|
||||
#include "dialbox.h"
|
||||
#include <qlayout.h>
|
||||
|
||||
DialTab::DialTab( QWidget *parent ):
|
||||
QWidget( parent )
|
||||
{
|
||||
QGridLayout *layout = new QGridLayout( this );
|
||||
|
||||
const int numRows = 3;
|
||||
for ( int i = 0; i < 2 * numRows; i++ )
|
||||
{
|
||||
DialBox *dialBox = new DialBox( this, i );
|
||||
layout->addWidget( dialBox, i / numRows, i % numRows );
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue