Add files from zip
This commit is contained in:
105
examples/scatterplot/Plot.cpp
Normal file
105
examples/scatterplot/Plot.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/*****************************************************************************
|
||||
* 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 <QwtPlotMagnifier>
|
||||
#include <QwtPlotPanner>
|
||||
#include <QwtPlotPicker>
|
||||
#include <QwtPickerMachine>
|
||||
#include <QwtPlotCurve>
|
||||
#include <QwtText>
|
||||
|
||||
#include <QPen>
|
||||
|
||||
namespace
|
||||
{
|
||||
class DistancePicker : public QwtPlotPicker
|
||||
{
|
||||
public:
|
||||
DistancePicker( QWidget* canvas )
|
||||
: QwtPlotPicker( canvas )
|
||||
{
|
||||
setTrackerMode( QwtPicker::ActiveOnly );
|
||||
setStateMachine( new QwtPickerDragLineMachine() );
|
||||
setRubberBand( QwtPlotPicker::PolygonRubberBand );
|
||||
}
|
||||
|
||||
virtual QwtText trackerTextF( const QPointF& pos ) const QWT_OVERRIDE
|
||||
{
|
||||
QwtText text;
|
||||
|
||||
const QPolygon points = selection();
|
||||
if ( !points.isEmpty() )
|
||||
{
|
||||
QString num;
|
||||
num.setNum( QLineF( pos, invTransform( points[0] ) ).length() );
|
||||
|
||||
QColor bg( Qt::white );
|
||||
bg.setAlpha( 200 );
|
||||
|
||||
text.setBackgroundBrush( QBrush( bg ) );
|
||||
text.setText( num );
|
||||
}
|
||||
return text;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Plot::Plot( QWidget* parent )
|
||||
: QwtPlot( parent )
|
||||
, m_curve( NULL )
|
||||
{
|
||||
canvas()->setStyleSheet(
|
||||
"border: 2px solid Black;"
|
||||
"border-radius: 15px;"
|
||||
"background-color: qlineargradient( x1: 0, y1: 0, x2: 0, y2: 1,"
|
||||
"stop: 0 LemonChiffon, stop: 1 PaleGoldenrod );"
|
||||
);
|
||||
|
||||
// attach curve
|
||||
m_curve = new QwtPlotCurve( "Scattered Points" );
|
||||
m_curve->setPen( QColor( "Purple" ) );
|
||||
|
||||
// when using QwtPlotCurve::ImageBuffer simple dots can be
|
||||
// rendered in parallel on multicore systems.
|
||||
m_curve->setRenderThreadCount( 0 ); // 0: use QThread::idealThreadCount()
|
||||
|
||||
m_curve->attach( this );
|
||||
|
||||
setSymbol( NULL );
|
||||
|
||||
// panning with the left mouse button
|
||||
(void )new QwtPlotPanner( canvas() );
|
||||
|
||||
// zoom in/out with the wheel
|
||||
QwtPlotMagnifier* magnifier = new QwtPlotMagnifier( canvas() );
|
||||
magnifier->setMouseButton( Qt::NoButton );
|
||||
|
||||
// distanve measurement with the right mouse button
|
||||
DistancePicker* picker = new DistancePicker( canvas() );
|
||||
picker->setMousePattern( QwtPlotPicker::MouseSelect1, Qt::RightButton );
|
||||
picker->setRubberBandPen( QPen( Qt::blue ) );
|
||||
}
|
||||
|
||||
void Plot::setSymbol( QwtSymbol* symbol )
|
||||
{
|
||||
m_curve->setSymbol( symbol );
|
||||
|
||||
if ( symbol == NULL )
|
||||
{
|
||||
m_curve->setStyle( QwtPlotCurve::Dots );
|
||||
}
|
||||
}
|
||||
|
||||
void Plot::setSamples( const QVector< QPointF >& samples )
|
||||
{
|
||||
m_curve->setPaintAttribute(
|
||||
QwtPlotCurve::ImageBuffer, samples.size() > 1000 );
|
||||
|
||||
m_curve->setSamples( samples );
|
||||
}
|
||||
|
||||
#include "moc_Plot.cpp"
|
||||
25
examples/scatterplot/Plot.h
Normal file
25
examples/scatterplot/Plot.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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 QwtPlotCurve;
|
||||
class QwtSymbol;
|
||||
|
||||
class Plot : public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Plot( QWidget* parent = NULL );
|
||||
|
||||
void setSymbol( QwtSymbol* );
|
||||
void setSamples( const QVector< QPointF >& samples );
|
||||
|
||||
private:
|
||||
QwtPlotCurve* m_curve;
|
||||
};
|
||||
53
examples/scatterplot/main.cpp
Normal file
53
examples/scatterplot/main.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/*****************************************************************************
|
||||
* 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 <QwtMath>
|
||||
#include <QApplication>
|
||||
|
||||
static inline double randomValue()
|
||||
{
|
||||
// a number between [ 0.0, 1.0 ]
|
||||
return ( qwtRand() % 100000 ) / 100000.0;
|
||||
}
|
||||
|
||||
class ScatterPlot : public Plot
|
||||
{
|
||||
public:
|
||||
ScatterPlot()
|
||||
{
|
||||
setTitle( "Scatter Plot" );
|
||||
|
||||
// a million points
|
||||
|
||||
const int numPoints = 100000;
|
||||
|
||||
QPolygonF samples;
|
||||
samples.reserve( numPoints );
|
||||
|
||||
for ( int i = 0; i < numPoints; i++ )
|
||||
{
|
||||
const double x = randomValue() * 24.0 + 1.0;
|
||||
const double y = std::log( 10.0 * ( x - 1.0 ) + 1.0 )
|
||||
* ( randomValue() * 0.5 + 0.9 );
|
||||
|
||||
samples += QPointF( x, y );
|
||||
}
|
||||
|
||||
setSamples( samples );
|
||||
}
|
||||
};
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
|
||||
ScatterPlot plot;
|
||||
plot.resize( 800, 600 );
|
||||
plot.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
16
examples/scatterplot/scatterplot.pro
Normal file
16
examples/scatterplot/scatterplot.pro
Normal file
@@ -0,0 +1,16 @@
|
||||
######################################################################
|
||||
# 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 = scatterplot
|
||||
|
||||
HEADERS = \
|
||||
Plot.h
|
||||
|
||||
SOURCES = \
|
||||
Plot.cpp \
|
||||
main.cpp
|
||||
|
||||
Reference in New Issue
Block a user