Released version 6.1.3
This commit is contained in:
commit
a94503cb82
1885 changed files with 276310 additions and 0 deletions
13
examples/scatterplot/main.cpp
Normal file
13
examples/scatterplot/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( 800, 600 );
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
35
examples/scatterplot/mainwindow.cpp
Normal file
35
examples/scatterplot/mainwindow.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "mainwindow.h"
|
||||
#include "plot.h"
|
||||
#include <qmath.h>
|
||||
|
||||
static double randomValue()
|
||||
{
|
||||
// a number between [ 0.0, 1.0 ]
|
||||
return ( qrand() % 100000 ) / 100000.0;
|
||||
}
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
d_plot = new Plot( this );
|
||||
d_plot->setTitle( "Scatter Plot" );
|
||||
setCentralWidget( d_plot );
|
||||
|
||||
// a million points
|
||||
setSamples( 100000 );
|
||||
}
|
||||
|
||||
void MainWindow::setSamples( int numPoints )
|
||||
{
|
||||
QPolygonF samples;
|
||||
|
||||
for ( int i = 0; i < numPoints; i++ )
|
||||
{
|
||||
const double x = randomValue() * 24.0 + 1.0;
|
||||
const double y = ::log( 10.0 * ( x - 1.0 ) + 1.0 )
|
||||
* ( randomValue() * 0.5 + 0.9 );
|
||||
|
||||
samples += QPointF( x, y );
|
||||
}
|
||||
|
||||
d_plot->setSamples( samples );
|
||||
}
|
22
examples/scatterplot/mainwindow.h
Normal file
22
examples/scatterplot/mainwindow.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef _MAINWINDOW_H_
|
||||
#define _MAINWINDOW_H_ 1
|
||||
|
||||
#include <qmainwindow.h>
|
||||
|
||||
class Plot;
|
||||
|
||||
class MainWindow: public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
|
||||
private:
|
||||
void setSamples( int samples );
|
||||
|
||||
private:
|
||||
Plot *d_plot;
|
||||
};
|
||||
|
||||
#endif
|
91
examples/scatterplot/plot.cpp
Normal file
91
examples/scatterplot/plot.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
#include "plot.h"
|
||||
#include <qwt_plot_magnifier.h>
|
||||
#include <qwt_plot_panner.h>
|
||||
#include <qwt_plot_picker.h>
|
||||
#include <qwt_picker_machine.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
|
||||
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
|
||||
{
|
||||
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 ),
|
||||
d_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
|
||||
d_curve = new QwtPlotCurve( "Scattered Points" );
|
||||
d_curve->setPen( QColor( "Purple" ) );
|
||||
|
||||
// when using QwtPlotCurve::ImageBuffer simple dots can be
|
||||
// rendered in parallel on multicore systems.
|
||||
d_curve->setRenderThreadCount( 0 ); // 0: use QThread::idealThreadCount()
|
||||
|
||||
d_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 )
|
||||
{
|
||||
d_curve->setSymbol( symbol );
|
||||
|
||||
if ( symbol == NULL )
|
||||
{
|
||||
d_curve->setStyle( QwtPlotCurve::Dots );
|
||||
}
|
||||
}
|
||||
|
||||
void Plot::setSamples( const QVector<QPointF> &samples )
|
||||
{
|
||||
d_curve->setPaintAttribute(
|
||||
QwtPlotCurve::ImageBuffer, samples.size() > 1000 );
|
||||
|
||||
d_curve->setSamples( samples );
|
||||
}
|
23
examples/scatterplot/plot.h
Normal file
23
examples/scatterplot/plot.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef _PLOT_H_
|
||||
#define _PLOT_H_ 1
|
||||
|
||||
#include <qwt_plot.h>
|
||||
|
||||
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 *d_curve;
|
||||
};
|
||||
|
||||
#endif // _PLOT_H_
|
22
examples/scatterplot/scatterplot.pro
Normal file
22
examples/scatterplot/scatterplot.pro
Normal file
|
@ -0,0 +1,22 @@
|
|||
################################################################
|
||||
# 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 = scatterplot
|
||||
|
||||
HEADERS = \
|
||||
mainwindow.h \
|
||||
plot.h
|
||||
|
||||
SOURCES = \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
plot.cpp
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue