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,132 @@
/*****************************************************************************
* 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 "TransformPlot.h"
#include <QwtTransform>
#include <QwtMath>
#include <QSplitter>
namespace
{
class TransformPos : public QwtTransform
{
public:
TransformPos( double pos, double range, double factor )
: m_position( pos )
, m_range( range )
, m_factor( factor )
, m_powRange( std::pow( m_range, m_factor ) )
{
}
virtual double transform( double value ) const QWT_OVERRIDE
{
const double v1 = m_position - m_range;
const double v2 = v1 + 2 * m_range;
if ( value <= v1 )
{
return value;
}
if ( value >= v2 )
{
return v1 + 2 * m_powRange + value - v2;
}
double v;
if ( value <= m_position )
{
v = v1 + std::pow( value - v1, m_factor );
}
else
{
v = v1 + 2 * m_powRange - std::pow( v2 - value, m_factor );
}
return v;
}
virtual double invTransform( double value ) const QWT_OVERRIDE
{
const double v1 = m_position - m_range;
const double v2 = v1 + 2 * m_powRange;
if ( value < v1 )
{
return value;
}
if ( value >= v2 )
{
return value + 2 * ( m_range - m_powRange );
}
double v;
if ( value <= v1 + m_powRange )
{
v = v1 + std::pow( value - v1, 1.0 / m_factor );
}
else
{
v = m_position + m_range - std::pow( v2 - value, 1.0 / m_factor );
}
return v;
}
virtual QwtTransform* copy() const QWT_OVERRIDE
{
return new TransformPos( m_position, m_range, m_factor );
}
private:
const double m_position;
const double m_range;
const double m_factor;
const double m_powRange;
};
}
MainWindow::MainWindow( QWidget* parent ):
QMainWindow( parent )
{
QSplitter* splitter = new QSplitter( Qt::Vertical );
m_transformPlot = new TransformPlot( splitter );
m_transformPlot->insertTransformation( "Square Root",
QColor( "DarkSlateGray" ), new QwtPowerTransform( 0.5 ) );
m_transformPlot->insertTransformation( "Linear",
QColor( "Peru" ), new QwtNullTransform() );
m_transformPlot->insertTransformation( "Cubic",
QColor( "OliveDrab" ), new QwtPowerTransform( 3.0 ) );
m_transformPlot->insertTransformation( "Power 10",
QColor( "Indigo" ), new QwtPowerTransform( 10.0 ) );
m_transformPlot->insertTransformation( "Log",
QColor( "SteelBlue" ), new QwtLogTransform() );
m_transformPlot->insertTransformation( "At 400",
QColor( "Crimson" ), new TransformPos( 400.0, 100.0, 1.4 ) );
const QwtPlotItemList curves =
m_transformPlot->itemList( QwtPlotItem::Rtti_PlotCurve );
if ( !curves.isEmpty() )
m_transformPlot->setLegendChecked( curves[ 2 ] );
m_plot = new Plot( splitter );
m_plot->setTransformation( new QwtPowerTransform( 3.0 ) );
setCentralWidget( splitter );
connect( m_transformPlot, SIGNAL(selected(QwtTransform*)),
m_plot, SLOT(setTransformation(QwtTransform*)) );
}
#include "moc_MainWindow.cpp"

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
*****************************************************************************/
#pragma once
#include <QMainWindow>
class Plot;
class TransformPlot;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget* parent = 0 );
private:
Plot* m_plot;
TransformPlot* m_transformPlot;
};

View File

@@ -0,0 +1,79 @@
/*****************************************************************************
* 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 <QwtPlotCurve>
#include <QwtPlotGrid>
#include <QwtSymbol>
#include <QwtPlotPicker>
#include <QwtScaleEngine>
#include <QwtTransform>
Plot::Plot( QWidget* parent )
: QwtPlot( parent )
{
setCanvasBackground( Qt::white );
setAxisScale( QwtAxis::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( QwtAxis::XBottom, scaleEngine );
// we have to reassign the axis settings, because they are
// invalidated, when the scale engine has changed
QwtScaleDiv scaleDiv =
axisScaleEngine( QwtAxis::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( QwtAxis::XBottom, scaleDiv );
replot();
}
#include "moc_Plot.cpp"

View File

@@ -0,0 +1,24 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include <QwtPlot>
class QwtTransform;
class Plot : public QwtPlot
{
Q_OBJECT
public:
Plot( QWidget* parent = NULL );
public Q_SLOTS:
void setTransformation( QwtTransform* );
private:
void populate();
};

View File

@@ -0,0 +1,118 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "TransformPlot.h"
#include <QwtPlotCurve>
#include <QwtSyntheticPointData>
#include <QwtTransform>
#include <QwtLegend>
#include <QwtLegendLabel>
namespace
{
class TransformData : public QwtSyntheticPointData
{
public:
TransformData( QwtTransform* transform )
: QwtSyntheticPointData( 200 )
, m_transform( transform )
{
}
virtual ~TransformData()
{
delete m_transform;
}
const QwtTransform* transform() const
{
return m_transform;
}
virtual double y( double x ) const QWT_OVERRIDE
{
const double min = 10.0;
const double max = 1000.0;
const double value = min + x * ( max - min );
const double s1 = m_transform->transform( min );
const double s2 = m_transform->transform( max );
const double s = m_transform->transform( value );
return ( s - s1 ) / ( s2 - s1 );
}
private:
const QwtTransform* m_transform;
};
}
TransformPlot::TransformPlot( QWidget* parent )
: QwtPlot( parent )
{
setTitle( "Transformations" );
setCanvasBackground( Qt::white );
setAxisScale( QwtAxis::XBottom, 0.0, 1.0 );
setAxisScale( QwtAxis::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* curveData = static_cast< TransformData* >( curve->data() );
Q_EMIT selected( curveData->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 );
}
}
}
}
#include "moc_TransformPlot.cpp"

View File

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

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( 800, 600 );
window.show();
return app.exec();
}

View File

@@ -0,0 +1,20 @@
######################################################################
# Qwt Examples - Copyright (C) 2002 Uwe Rathmann
# This file may be used under the terms of the 3-clause BSD License
######################################################################
include( $${PWD}/../playground.pri )
TARGET = scaleengine
HEADERS = \
TransformPlot.h \
Plot.h \
MainWindow.h
SOURCES = \
TransformPlot.cpp \
Plot.cpp \
MainWindow.cpp \
main.cpp