Released version 6.1.3
This commit is contained in:
commit
a94503cb82
1885 changed files with 276310 additions and 0 deletions
120
playground/scaleengine/mainwindow.cpp
Normal file
120
playground/scaleengine/mainwindow.cpp
Normal file
|
@ -0,0 +1,120 @@
|
|||
#include "mainwindow.h"
|
||||
#include "plot.h"
|
||||
#include "transformplot.h"
|
||||
#include <qwt_transform.h>
|
||||
#include <qsplitter.h>
|
||||
#include <qmath.h>
|
||||
|
||||
class TransformPos: public QwtTransform
|
||||
{
|
||||
public:
|
||||
TransformPos( double pos, double range, double factor ):
|
||||
d_position( pos ),
|
||||
d_range( range ),
|
||||
d_factor( factor ),
|
||||
d_powRange( qPow( d_range, d_factor ) )
|
||||
{
|
||||
}
|
||||
|
||||
virtual double transform( double value ) const
|
||||
{
|
||||
const double v1 = d_position - d_range;
|
||||
const double v2 = v1 + 2 * d_range;
|
||||
|
||||
if ( value <= v1 )
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
if ( value >= v2 )
|
||||
{
|
||||
return v1 + 2 * d_powRange + value - v2;
|
||||
}
|
||||
|
||||
double v;
|
||||
|
||||
if ( value <= d_position )
|
||||
{
|
||||
v = v1 + qPow( value - v1, d_factor );
|
||||
}
|
||||
else
|
||||
{
|
||||
v = v1 + 2 * d_powRange - qPow( v2 - value, d_factor );
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
virtual double invTransform( double value ) const
|
||||
{
|
||||
const double v1 = d_position - d_range;
|
||||
const double v2 = v1 + 2 * d_powRange;
|
||||
|
||||
if ( value < v1 )
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
if ( value >= v2 )
|
||||
{
|
||||
return value + 2 * ( d_range - d_powRange );
|
||||
}
|
||||
|
||||
double v;
|
||||
if ( value <= v1 + d_powRange )
|
||||
{
|
||||
v = v1 + qPow( value - v1, 1.0 / d_factor );
|
||||
}
|
||||
else
|
||||
{
|
||||
v = d_position + d_range - qPow( v2 - value, 1.0 / d_factor );
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
virtual QwtTransform *copy() const
|
||||
{
|
||||
return new TransformPos( d_position, d_range, d_factor );
|
||||
}
|
||||
|
||||
private:
|
||||
const double d_position;
|
||||
const double d_range;
|
||||
const double d_factor;
|
||||
const double d_powRange;
|
||||
};
|
||||
|
||||
MainWindow::MainWindow( QWidget *parent ):
|
||||
QMainWindow( parent )
|
||||
{
|
||||
QSplitter *splitter = new QSplitter( Qt::Vertical );
|
||||
|
||||
d_transformPlot = new TransformPlot( splitter );
|
||||
|
||||
d_transformPlot->insertTransformation( "Square Root",
|
||||
QColor( "DarkSlateGray" ), new QwtPowerTransform( 0.5 ) );
|
||||
d_transformPlot->insertTransformation( "Linear",
|
||||
QColor( "Peru" ), new QwtNullTransform() );
|
||||
d_transformPlot->insertTransformation( "Cubic",
|
||||
QColor( "OliveDrab" ), new QwtPowerTransform( 3.0 ) );
|
||||
d_transformPlot->insertTransformation( "Power 10",
|
||||
QColor( "Indigo" ), new QwtPowerTransform( 10.0 ) );
|
||||
d_transformPlot->insertTransformation( "Log",
|
||||
QColor( "SteelBlue" ), new QwtLogTransform() );
|
||||
d_transformPlot->insertTransformation( "At 400",
|
||||
QColor( "Crimson" ), new TransformPos( 400.0, 100.0, 1.4 ) );
|
||||
|
||||
const QwtPlotItemList curves =
|
||||
d_transformPlot->itemList( QwtPlotItem::Rtti_PlotCurve );
|
||||
if ( !curves.isEmpty() )
|
||||
d_transformPlot->setLegendChecked( curves[ 2 ] );
|
||||
|
||||
d_plot = new Plot( splitter );
|
||||
d_plot->setTransformation( new QwtPowerTransform( 3.0 ) );
|
||||
|
||||
setCentralWidget( splitter );
|
||||
|
||||
connect( d_transformPlot, SIGNAL( selected( QwtTransform * ) ),
|
||||
d_plot, SLOT( setTransformation( QwtTransform * ) ) );
|
||||
}
|
16
playground/scaleengine/mainwindow.h
Normal file
16
playground/scaleengine/mainwindow.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include <qmainwindow.h>
|
||||
|
||||
class Plot;
|
||||
class TransformPlot;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow( QWidget *parent = 0 );
|
||||
|
||||
private:
|
||||
Plot *d_plot;
|
||||
TransformPlot *d_transformPlot;
|
||||
};
|
70
playground/scaleengine/plot.cpp
Normal file
70
playground/scaleengine/plot.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#include "plot.h"
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_plot_grid.h>
|
||||
#include <qwt_symbol.h>
|
||||
#include <qwt_plot_picker.h>
|
||||
#include <qwt_scale_engine.h>
|
||||
|
||||
Plot::Plot( QWidget *parent ):
|
||||
QwtPlot( parent )
|
||||
{
|
||||
setCanvasBackground( Qt::white );
|
||||
|
||||
setAxisScale(QwtPlot::yLeft, 0.0, 10.0 );
|
||||
setTransformation( new QwtNullTransform() );
|
||||
|
||||
populate();
|
||||
|
||||
QwtPlotPicker *picker = new QwtPlotPicker( canvas() );
|
||||
picker->setTrackerMode( QwtPlotPicker::AlwaysOn );
|
||||
}
|
||||
|
||||
void Plot::populate()
|
||||
{
|
||||
QwtPlotGrid *grid = new QwtPlotGrid();
|
||||
grid->setMinorPen( Qt::black, 0, Qt::DashLine );
|
||||
grid->enableXMin( true );
|
||||
grid->attach( this );
|
||||
|
||||
QwtPlotCurve *curve = new QwtPlotCurve();
|
||||
curve->setTitle("Some Points");
|
||||
curve->setPen( Qt::blue, 4 ),
|
||||
curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
|
||||
|
||||
QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
|
||||
QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
|
||||
curve->setSymbol( symbol );
|
||||
|
||||
QPolygonF points;
|
||||
points << QPointF( 10.0, 4.4 )
|
||||
<< QPointF( 100.0, 3.0 ) << QPointF( 200.0, 4.5 )
|
||||
<< QPointF( 300.0, 6.8 ) << QPointF( 400.0, 7.9 )
|
||||
<< QPointF( 500.0, 7.1 ) << QPointF( 600.0, 7.9 )
|
||||
<< QPointF( 700.0, 7.1 ) << QPointF( 800.0, 5.4 )
|
||||
<< QPointF( 900.0, 2.8 ) << QPointF( 1000.0, 3.6 );
|
||||
curve->setSamples( points );
|
||||
curve->attach( this );
|
||||
}
|
||||
|
||||
void Plot::setTransformation( QwtTransform *transform )
|
||||
{
|
||||
QwtLinearScaleEngine *scaleEngine = new QwtLinearScaleEngine();
|
||||
scaleEngine->setTransformation( transform );
|
||||
|
||||
setAxisScaleEngine( QwtPlot::xBottom, scaleEngine );
|
||||
|
||||
// we have to reassign the axis settinge, because they are
|
||||
// invalidated, when the scale engine has changed
|
||||
|
||||
QwtScaleDiv scaleDiv =
|
||||
axisScaleEngine( QwtPlot::xBottom )->divideScale( 10.0, 1000.0, 8, 10 );
|
||||
|
||||
QList<double> ticks;
|
||||
ticks += 10.0;
|
||||
ticks += scaleDiv.ticks( QwtScaleDiv::MajorTick );
|
||||
scaleDiv.setTicks( QwtScaleDiv::MajorTick, ticks );
|
||||
|
||||
setAxisScaleDiv( QwtPlot::xBottom, scaleDiv );
|
||||
|
||||
replot();
|
||||
}
|
23
playground/scaleengine/plot.h
Normal file
23
playground/scaleengine/plot.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef _PLOT_H_
|
||||
#define _PLOT_H_
|
||||
|
||||
#include <qwt_plot.h>
|
||||
|
||||
class QwtTransform;
|
||||
|
||||
class Plot: public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Plot( QWidget *parent = NULL );
|
||||
|
||||
public Q_SLOTS:
|
||||
void setTransformation( QwtTransform * );
|
||||
|
||||
private:
|
||||
void populate();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
13
playground/scaleengine/scaleengine.cpp
Normal file
13
playground/scaleengine/scaleengine.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <qapplication.h>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
MainWindow window;
|
||||
window.resize(800,600);
|
||||
window.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
24
playground/scaleengine/scaleengine.pro
Normal file
24
playground/scaleengine/scaleengine.pro
Normal file
|
@ -0,0 +1,24 @@
|
|||
################################################################
|
||||
# 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}/../playground.pri )
|
||||
|
||||
TARGET = scaleengine
|
||||
|
||||
HEADERS = \
|
||||
transformplot.h \
|
||||
plot.h \
|
||||
mainwindow.h
|
||||
|
||||
SOURCES = \
|
||||
transformplot.cpp \
|
||||
plot.cpp \
|
||||
mainwindow.cpp \
|
||||
scaleengine.cpp
|
||||
|
108
playground/scaleengine/transformplot.cpp
Normal file
108
playground/scaleengine/transformplot.cpp
Normal file
|
@ -0,0 +1,108 @@
|
|||
#include "transformplot.h"
|
||||
#include <qwt_curve_fitter.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_point_data.h>
|
||||
#include <qwt_transform.h>
|
||||
#include <qwt_legend.h>
|
||||
#include <qwt_legend_label.h>
|
||||
|
||||
class TransformData: public QwtSyntheticPointData
|
||||
{
|
||||
public:
|
||||
TransformData( QwtTransform *transform ):
|
||||
QwtSyntheticPointData( 200 ),
|
||||
d_transform( transform )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~TransformData()
|
||||
{
|
||||
delete d_transform;
|
||||
}
|
||||
|
||||
const QwtTransform *transform() const
|
||||
{
|
||||
return d_transform;
|
||||
}
|
||||
|
||||
virtual double y( double x ) const
|
||||
{
|
||||
const double min = 10.0;
|
||||
const double max = 1000.0;
|
||||
|
||||
const double value = min + x * ( max - min );
|
||||
|
||||
const double s1 = d_transform->transform( min );
|
||||
const double s2 = d_transform->transform( max );
|
||||
const double s = d_transform->transform( value );
|
||||
|
||||
return ( s - s1 ) / ( s2 - s1 );
|
||||
}
|
||||
|
||||
private:
|
||||
QwtTransform *d_transform;
|
||||
};
|
||||
|
||||
TransformPlot::TransformPlot( QWidget *parent ):
|
||||
QwtPlot( parent )
|
||||
{
|
||||
setTitle( "Transformations" );
|
||||
setCanvasBackground( Qt::white );
|
||||
|
||||
setAxisScale( QwtPlot::xBottom, 0.0, 1.0 );
|
||||
setAxisScale( QwtPlot::yLeft, 0.0, 1.0 );
|
||||
|
||||
QwtLegend *legend = new QwtLegend();
|
||||
legend->setDefaultItemMode( QwtLegendData::Checkable );
|
||||
insertLegend( legend, QwtPlot::RightLegend );
|
||||
|
||||
connect( legend, SIGNAL( checked( const QVariant &, bool, int ) ),
|
||||
this, SLOT( legendChecked( const QVariant &, bool ) ) );
|
||||
}
|
||||
|
||||
void TransformPlot::insertTransformation(
|
||||
const QString &title, const QColor &color, QwtTransform *transform )
|
||||
{
|
||||
QwtPlotCurve *curve = new QwtPlotCurve( title );
|
||||
curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
|
||||
curve->setPen( color, 2 );
|
||||
curve->setData( new TransformData( transform ) );
|
||||
curve->attach( this );
|
||||
}
|
||||
|
||||
void TransformPlot::legendChecked( const QVariant &itemInfo, bool on )
|
||||
{
|
||||
QwtPlotItem *plotItem = infoToItem( itemInfo );
|
||||
|
||||
setLegendChecked( plotItem );
|
||||
|
||||
if ( on && plotItem->rtti() == QwtPlotItem::Rtti_PlotCurve )
|
||||
{
|
||||
QwtPlotCurve *curve = static_cast<QwtPlotCurve *>( plotItem );
|
||||
TransformData *data = static_cast<TransformData *>( curve->data() );
|
||||
|
||||
Q_EMIT selected( data->transform()->copy() );
|
||||
}
|
||||
}
|
||||
|
||||
void TransformPlot::setLegendChecked( QwtPlotItem *plotItem )
|
||||
{
|
||||
const QwtPlotItemList items = itemList();
|
||||
for ( int i = 0; i < items.size(); i++ )
|
||||
{
|
||||
QwtPlotItem *item = items[ i ];
|
||||
if ( item->testItemAttribute( QwtPlotItem::Legend ) )
|
||||
{
|
||||
QwtLegend *lgd = qobject_cast<QwtLegend *>( legend() );
|
||||
|
||||
QwtLegendLabel *label = qobject_cast< QwtLegendLabel *>(
|
||||
lgd->legendWidget( itemToInfo( item ) ) );
|
||||
if ( label )
|
||||
{
|
||||
lgd->blockSignals( true );
|
||||
label->setChecked( item == plotItem );
|
||||
lgd->blockSignals( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
27
playground/scaleengine/transformplot.h
Normal file
27
playground/scaleengine/transformplot.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef _TRANSFORM_PLOT_H_
|
||||
#define _TRANSFORM_PLOT_H_
|
||||
|
||||
#include <qwt_plot.h>
|
||||
|
||||
class TransformPlot: public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TransformPlot( QWidget *parent = NULL );
|
||||
void insertTransformation( const QString &,
|
||||
const QColor &, QwtTransform * );
|
||||
|
||||
void setLegendChecked( QwtPlotItem * );
|
||||
|
||||
Q_SIGNALS:
|
||||
void selected( QwtTransform * );
|
||||
|
||||
private Q_SLOTS:
|
||||
void legendChecked( const QVariant &, bool on );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue