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,137 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "CurveTracker.h"
#include <QwtPickerMachine>
#include <QwtPlot>
#include <QwtPlotCurve>
#include <QwtText>
#include <QPen>
struct compareX
{
inline bool operator()( const double x, const QPointF& pos ) const
{
return ( x < pos.x() );
}
};
CurveTracker::CurveTracker( QWidget* canvas )
: QwtPlotPicker( canvas )
{
setTrackerMode( QwtPlotPicker::ActiveOnly );
setRubberBand( VLineRubberBand );
setStateMachine( new QwtPickerDragPointMachine() );
}
QRect CurveTracker::trackerRect( const QFont& font ) const
{
QRect r = QwtPlotPicker::trackerRect( font );
// align r to the first curve
const QwtPlotItemList curves = plot()->itemList( QwtPlotItem::Rtti_PlotCurve );
if ( curves.size() > 0 )
{
QPointF pos = invTransform( trackerPosition() );
const QLineF line = curveLineAt(
static_cast< const QwtPlotCurve* >( curves[0] ), pos.x() );
if ( !line.isNull() )
{
const double curveY = line.pointAt(
( pos.x() - line.p1().x() ) / line.dx() ).y();
pos.setY( curveY );
pos = transform( pos );
r.moveBottom( pos.y() );
}
}
return r;
}
QwtText CurveTracker::trackerTextF( const QPointF& pos ) const
{
QwtText trackerText;
trackerText.setColor( Qt::black );
QColor c( "#333333" );
trackerText.setBorderPen( QPen( c, 2 ) );
c.setAlpha( 200 );
trackerText.setBackgroundBrush( c );
QString info;
const QwtPlotItemList curves =
plot()->itemList( QwtPlotItem::Rtti_PlotCurve );
for ( int i = 0; i < curves.size(); i++ )
{
const QString curveInfo = curveInfoAt(
static_cast< const QwtPlotCurve* >( curves[i] ), pos );
if ( !curveInfo.isEmpty() )
{
if ( !info.isEmpty() )
info += "<br>";
info += curveInfo;
}
}
trackerText.setText( info );
return trackerText;
}
QString CurveTracker::curveInfoAt(
const QwtPlotCurve* curve, const QPointF& pos ) const
{
const QLineF line = curveLineAt( curve, pos.x() );
if ( line.isNull() )
return QString();
const double y = line.pointAt(
( pos.x() - line.p1().x() ) / line.dx() ).y();
QString info( "<font color=" "%1" ">%2</font>" );
return info.arg( curve->pen().color().name() ).arg( y );
}
QLineF CurveTracker::curveLineAt(
const QwtPlotCurve* curve, double x ) const
{
QLineF line;
if ( curve->dataSize() >= 2 )
{
const QRectF br = curve->boundingRect();
if ( ( br.width() > 0 ) && ( x >= br.left() ) && ( x <= br.right() ) )
{
int index = qwtUpperSampleIndex< QPointF >(
*curve->data(), x, compareX() );
if ( index == -1 &&
x == curve->sample( curve->dataSize() - 1 ).x() )
{
// the last sample is excluded from qwtUpperSampleIndex
index = curve->dataSize() - 1;
}
if ( index > 0 )
{
line.setP1( curve->sample( index - 1 ) );
line.setP2( curve->sample( index ) );
}
}
}
return line;
}

View 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 <QwtPlotPicker>
class QwtPlotCurve;
class QLineF;
class CurveTracker : public QwtPlotPicker
{
public:
CurveTracker( QWidget* );
protected:
virtual QwtText trackerTextF( const QPointF& ) const QWT_OVERRIDE;
virtual QRect trackerRect( const QFont& ) const QWT_OVERRIDE;
private:
QString curveInfoAt( const QwtPlotCurve*, const QPointF& ) const;
QLineF curveLineAt( const QwtPlotCurve*, double x ) const;
};

View File

@@ -0,0 +1,112 @@
/*****************************************************************************
* 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 "CurveTracker.h"
#include <QwtPickerMachine>
#include <QwtPlotCanvas>
#include <QwtPlotGrid>
#include <QwtPlotTextLabel>
#include <QwtPlotZoneItem>
#include <QwtPlotCurve>
#include <QwtPlotLayout>
#include <QwtScaleWidget>
#include <QwtSymbol>
Plot::Plot( QWidget* parent )
: QwtPlot( parent)
{
setPalette( Qt::black );
// we want to have the axis scales like a frame around the
// canvas
plotLayout()->setAlignCanvasToScales( true );
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
axisWidget( axisPos )->setMargin( 0 );
QwtPlotCanvas* canvas = new QwtPlotCanvas();
canvas->setAutoFillBackground( false );
canvas->setFrameStyle( QFrame::NoFrame );
setCanvas( canvas );
setAxisScale( QwtAxis::YLeft, 0.0, 10.0 );
// a title
QwtText title( "Picker Demo" );
title.setColor( Qt::white );
title.setRenderFlags( Qt::AlignHCenter | Qt::AlignTop );
QFont font;
font.setBold( true );
title.setFont( font );
QwtPlotTextLabel* titleItem = new QwtPlotTextLabel();
titleItem->setText( title );
titleItem->attach( this );
#if 1
// section
//QColor c( "PaleVioletRed" );
QwtPlotZoneItem* zone = new QwtPlotZoneItem();
zone->setPen( Qt::darkGray );
zone->setBrush( QColor( "#834358" ) );
zone->setOrientation( Qt::Horizontal );
zone->setInterval( 3.8, 5.7 );
zone->attach( this );
#else
// grid
QwtPlotGrid* grid = new QwtPlotGrid();
grid->setMajorPen( Qt::white, 0, Qt::DotLine );
grid->setMinorPen( Qt::gray, 0, Qt::DotLine );
grid->attach( this );
#endif
// curves
QPolygonF points1;
points1 << QPointF( 0.2, 4.4 ) << QPointF( 1.2, 3.0 )
<< QPointF( 2.7, 4.5 ) << QPointF( 3.5, 6.8 )
<< QPointF( 4.7, 7.9 ) << QPointF( 5.8, 7.1 );
insertCurve( "Curve 1", "DarkOrange", points1 );
QPolygonF points2;
points2 << QPointF( 0.4, 8.7 ) << QPointF( 1.4, 7.8 )
<< QPointF( 2.3, 5.5 ) << QPointF( 3.3, 4.1 )
<< QPointF( 4.4, 5.2 ) << QPointF( 5.6, 5.7 );
insertCurve( "Curve 2", "DodgerBlue", points2 );
CurveTracker* tracker = new CurveTracker( this->canvas() );
// for the demo we want the tracker to be active without
// having to click on the canvas
tracker->setStateMachine( new QwtPickerTrackerMachine() );
tracker->setRubberBandPen( QPen( "MediumOrchid" ) );
}
void Plot::insertCurve( const QString& title,
const QColor& color, const QPolygonF& points )
{
QwtPlotCurve* curve = new QwtPlotCurve();
curve->setTitle( title );
curve->setPen( color, 2 ),
curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
QwtSymbol* symbol = new QwtSymbol( QwtSymbol::Ellipse,
QBrush( Qt::white ), QPen( color, 2 ), QSize( 8, 8 ) );
curve->setSymbol( symbol );
curve->setSamples( points );
curve->attach( this );
}
#include "moc_Plot.cpp"

View File

@@ -0,0 +1,22 @@
/*****************************************************************************
* 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 QPolygonF;
class Plot : public QwtPlot
{
Q_OBJECT
public:
Plot( QWidget* = NULL );
private:
void insertCurve( const QString& title,
const QColor&, const QPolygonF& );
};

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( $${PWD}/../playground.pri )
TARGET = curvetracker
HEADERS = \
CurveTracker.h \
Plot.h
SOURCES = \
CurveTracker.cpp \
Plot.cpp \
main.cpp

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 "Plot.h"
#include <QApplication>
int main( int argc, char* argv[] )
{
QApplication app( argc, argv );
Plot plot;
plot.resize( 600, 400 );
plot.show();
return app.exec();
}

View File

@@ -0,0 +1,77 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "Canvas.h"
#include <QwtGraphic>
#include <QSvgRenderer>
Canvas::Canvas( Mode mode, QWidget* parent )
: QWidget( parent )
, m_mode( mode )
{
const int m = 10;
setContentsMargins( m, m, m, m );
if ( m_mode == Svg )
m_renderer = new QSvgRenderer( this );
else
m_graphic = new QwtGraphic();
}
Canvas::~Canvas()
{
if ( m_mode == VectorGraphic )
delete m_graphic;
}
void Canvas::setSvg( const QByteArray& svgData )
{
if ( m_mode == VectorGraphic )
{
m_graphic->reset();
QSvgRenderer renderer;
renderer.load( svgData );
QPainter p( m_graphic );
renderer.render( &p, renderer.viewBoxF() );
p.end();
}
else
{
m_renderer->load( svgData );
}
update();
}
void Canvas::paintEvent( QPaintEvent* )
{
QPainter painter( this );
painter.save();
painter.setPen( Qt::black );
painter.setBrush( Qt::white );
painter.drawRect( contentsRect().adjusted( 0, 0, -1, -1 ) );
painter.restore();
painter.setPen( Qt::NoPen );
painter.setBrush( Qt::NoBrush );
render( &painter, contentsRect() );
}
void Canvas::render( QPainter* painter, const QRect& rect ) const
{
if ( m_mode == Svg )
{
m_renderer->render( painter, rect );
}
else
{
m_graphic->render( painter, rect );
}
}

View File

@@ -0,0 +1,40 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include <QwtGlobal>
#include <QWidget>
class QSvgRenderer;
class QwtGraphic;
class Canvas : public QWidget
{
public:
enum Mode
{
Svg,
VectorGraphic
};
Canvas( Mode, QWidget* parent = NULL );
virtual ~Canvas();
void setSvg( const QByteArray& );
protected:
virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE;
private:
void render( QPainter*, const QRect& ) const;
const Mode m_mode;
union
{
QSvgRenderer* m_renderer;
QwtGraphic* m_graphic;
};
};

View File

@@ -0,0 +1,117 @@
/*****************************************************************************
* 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 "Canvas.h"
#include <QToolBar>
#include <QToolButton>
#include <QLayout>
#include <QLabel>
#include <QFileDialog>
#include <QBuffer>
#include <QPainter>
#include <QSvgGenerator>
#include <QStatusBar>
MainWindow::MainWindow()
{
QWidget* w = new QWidget( this );
m_canvas[0] = new Canvas( Canvas::Svg, this );
m_canvas[0]->setAutoFillBackground( true );
m_canvas[0]->setPalette( Qt::gray );
m_canvas[1] = new Canvas( Canvas::VectorGraphic, this );
m_canvas[1]->setAutoFillBackground( true );
m_canvas[1]->setPalette( Qt::gray );
QVBoxLayout* vBox1 = new QVBoxLayout();
vBox1->setContentsMargins( 0, 0, 0, 0 );
vBox1->setSpacing( 5 );
vBox1->addWidget( new QLabel( "SVG" ), 0, Qt::AlignCenter );
vBox1->addWidget( m_canvas[0], 10 );
QVBoxLayout* vBox2 = new QVBoxLayout();
vBox2->setContentsMargins( 0, 0, 0, 0 );
vBox2->setSpacing( 5 );
vBox2->addWidget( new QLabel( "Vector Graphic" ), 0, Qt::AlignCenter );
vBox2->addWidget( m_canvas[1], 10 );
QHBoxLayout* layout = new QHBoxLayout( w );
layout->addLayout( vBox1 );
layout->addLayout( vBox2 );
setCentralWidget( w );
QToolBar* toolBar = new QToolBar( this );
QToolButton* btnLoad = new QToolButton( toolBar );
btnLoad->setText( "Load SVG" );
btnLoad->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
toolBar->addWidget( btnLoad );
addToolBar( toolBar );
connect( btnLoad, SIGNAL(clicked()), this, SLOT(loadSVG()) );
#if 0
QPainterPath path;
path.addRect( QRectF( 1.0, 1.0, 2.0, 2.0 ) );
loadPath( path );
#endif
}
MainWindow::~MainWindow()
{
}
void MainWindow::loadSVG()
{
QString dir = "/home1/uwe/qwt/qwt/tests/svg";
const QString fileName = QFileDialog::getOpenFileName( NULL,
"Load a Scaleable Vector Graphic (SVG) Document",
dir, "SVG Files (*.svg)" );
if ( !fileName.isEmpty() )
loadSVG( fileName );
statusBar()->showMessage( fileName );
}
void MainWindow::loadSVG( const QString& fileName )
{
QFile file( fileName );
if ( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
return;
const QByteArray document = file.readAll();
file.close();
m_canvas[0]->setSvg( document );
m_canvas[1]->setSvg( document );
}
void MainWindow::loadPath( const QPainterPath& path )
{
QBuffer buf;
QSvgGenerator generator;
generator.setOutputDevice( &buf );
QPainter painter( &generator );
painter.setRenderHint( QPainter::Antialiasing, false );
painter.setPen( QPen( Qt::blue, 0 ) );
painter.setBrush( Qt::darkCyan );
painter.drawPath( path );
painter.end();
m_canvas[0]->setSvg( buf.data() );
m_canvas[1]->setSvg( buf.data() );
}
#include "moc_MainWindow.cpp"

View File

@@ -0,0 +1,29 @@
/*****************************************************************************
* 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 Canvas;
class QPainterPath;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
virtual ~MainWindow();
private Q_SLOTS:
void loadSVG();
private:
void loadSVG( const QString& );
void loadPath( const QPainterPath& );
Canvas* m_canvas[2];
};

View 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
######################################################################
include( $${PWD}/../playground.pri )
greaterThan(QT_MAJOR_VERSION, 4) {
!qtHaveModule(svg) {
error("Qt has been built without SVG support !")
}
}
TARGET = graphicscale
QT += svg
HEADERS = \
Canvas.h \
MainWindow.h
SOURCES = \
Canvas.cpp \
MainWindow.cpp \
main.cpp

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

67
playground/playground.pri Normal file
View File

@@ -0,0 +1,67 @@
######################################################################
# Qwt Examples - Copyright (C) 2002 Uwe Rathmann
# This file may be used under the terms of the 3-clause BSD License
######################################################################
QWT_ROOT = $${PWD}/..
include( $${QWT_ROOT}/qwtconfig.pri )
include( $${QWT_ROOT}/qwtbuild.pri )
include( $${QWT_ROOT}/qwtfunctions.pri )
QWT_OUT_ROOT = $${OUT_PWD}/../..
TEMPLATE = app
INCLUDEPATH += $${QWT_ROOT}/src
DEPENDPATH += $${QWT_ROOT}/src
INCLUDEPATH += $${QWT_ROOT}/classincludes
DEPENDPATH += $${QWT_ROOT}/classincludes
!debug_and_release {
DESTDIR = $${QWT_OUT_ROOT}/playground/bin
}
else {
CONFIG(debug, debug|release) {
DESTDIR = $${QWT_OUT_ROOT}/playground/bin_debug
}
else {
DESTDIR = $${QWT_OUT_ROOT}/playground/bin
}
}
QMAKE_RPATHDIR *= $${QWT_ROOT}/lib
qwtAddLibrary($${QWT_OUT_ROOT}/lib, qwt)
greaterThan(QT_MAJOR_VERSION, 4) {
QT += printsupport
QT += concurrent
}
contains(QWT_CONFIG, QwtOpenGL ) {
QT += opengl
}
else {
DEFINES += QWT_NO_OPENGL
}
contains(QWT_CONFIG, QwtSvg) {
QT += svg
}
else {
DEFINES += QWT_NO_SVG
}
contains(QWT_CONFIG, QwtDll) {
DEFINES += QT_DLL QWT_DLL
}

39
playground/playground.pro Normal file
View File

@@ -0,0 +1,39 @@
######################################################################
# Qwt Examples - Copyright (C) 2002 Uwe Rathmann
# This file may be used under the terms of the 3-clause BSD License
######################################################################
include( $${PWD}/../qwtconfig.pri )
TEMPLATE = subdirs
contains(QWT_CONFIG, QwtPlot) {
SUBDIRS += \
plotmatrix \
timescale \
scaleengine \
rescaler \
shapes \
curvetracker \
vectorfield \
symbols
greaterThan(QT_MAJOR_VERSION, 4) {
qtHaveModule(svg) {
# we only need SVG support from Qt, but not from Qwt
CONFIG += svgexamples
}
}
else {
contains(QWT_CONFIG, QwtSvg) {
CONFIG += svgexamples
}
}
svgexamples {
SUBDIRS += \
svgmap \
graphicscale
}
}

View File

@@ -0,0 +1,426 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "PlotMatrix.h"
#include <QwtPlot>
#include <QwtPlotCanvas>
#include <QwtScaleWidget>
#include <QwtScaleDraw>
#include <QLayout>
static void enablePlotAxis( QwtPlot* plot, int axis, bool on )
{
// when false we still enable the axis to have an effect
// of the minimal extent active. Instead we hide all visible
// parts and margins/spacings.
plot->setAxisVisible( axis, true );
QwtScaleDraw* sd = plot->axisScaleDraw( axis );
sd->enableComponent( QwtScaleDraw::Backbone, on );
sd->enableComponent( QwtScaleDraw::Ticks, on );
sd->enableComponent( QwtScaleDraw::Labels, on );
QwtScaleWidget* sw = plot->axisWidget( axis );
sw->setMargin( on ? 4 : 0 );
sw->setSpacing( on ? 20 : 0 );
}
namespace
{
class Plot : public QwtPlot
{
public:
Plot( QWidget* parent = NULL )
: QwtPlot( parent )
{
QwtPlotCanvas* canvas = new QwtPlotCanvas();
canvas->setLineWidth( 1 );
canvas->setFrameStyle( QFrame::Box | QFrame::Plain );
setCanvas( canvas );
}
virtual QSize sizeHint() const QWT_OVERRIDE
{
return minimumSizeHint();
}
};
}
class PlotMatrix::PrivateData
{
public:
PrivateData():
inScaleSync( false )
{
isAxisEnabled[QwtAxis::XBottom] = true;
isAxisEnabled[QwtAxis::XTop] = false;
isAxisEnabled[QwtAxis::YLeft] = true;
isAxisEnabled[QwtAxis::YRight] = false;
}
bool isAxisEnabled[QwtAxis::AxisPositions];
QVector< QwtPlot* > plotWidgets;
mutable bool inScaleSync;
};
PlotMatrix::PlotMatrix( int numRows, int numColumns, QWidget* parent )
: QFrame( parent )
{
m_data = new PrivateData();
m_data->plotWidgets.resize( numRows * numColumns );
QGridLayout* layout = new QGridLayout( this );
layout->setSpacing( 5 );
for ( int row = 0; row < numRows; row++ )
{
for ( int col = 0; col < numColumns; col++ )
{
QwtPlot* plot = new Plot( this );
layout->addWidget( plot, row, col );
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
{
connect( plot->axisWidget( axisPos ),
SIGNAL(scaleDivChanged()), SLOT(scaleDivChanged()),
Qt::QueuedConnection );
}
m_data->plotWidgets[row * numColumns + col] = plot;
}
}
updateLayout();
}
PlotMatrix::~PlotMatrix()
{
delete m_data;
}
int PlotMatrix::numRows() const
{
const QGridLayout* l = qobject_cast< const QGridLayout* >( layout() );
if ( l )
return l->rowCount();
return 0;
}
int PlotMatrix::numColumns() const
{
const QGridLayout* l = qobject_cast< const QGridLayout* >( layout() );
if ( l )
return l->columnCount();
return 0;
}
QwtPlot* PlotMatrix::plotAt( int row, int column )
{
const int index = row * numColumns() + column;
if ( index < m_data->plotWidgets.size() )
return m_data->plotWidgets[index];
return NULL;
}
const QwtPlot* PlotMatrix::plotAt( int row, int column ) const
{
const int index = row * numColumns() + column;
if ( index < m_data->plotWidgets.size() )
return m_data->plotWidgets[index];
return NULL;
}
void PlotMatrix::setAxisVisible( int axis, bool tf )
{
if ( QwtAxis::isValid( axis ) )
{
if ( tf != m_data->isAxisEnabled[axis] )
{
m_data->isAxisEnabled[axis] = tf;
updateLayout();
}
}
}
bool PlotMatrix::isAxisVisible( int axis ) const
{
if ( QwtAxis::isValid( axis ) )
return m_data->isAxisEnabled[axis];
return false;
}
void PlotMatrix::setAxisScale( int axis, int rowOrColumn,
double min, double max, double step )
{
int row = 0;
int col = 0;
if ( QwtAxis::isXAxis( axis ) )
col = rowOrColumn;
else
row = rowOrColumn;
QwtPlot* plt = plotAt( row, col );
if ( plt )
{
plt->setAxisScale( axis, min, max, step );
plt->updateAxes();
}
}
void PlotMatrix::scaleDivChanged()
{
if ( m_data->inScaleSync )
return;
m_data->inScaleSync = true;
QwtPlot* plt = NULL;
int axisId = -1;
int rowOrColumn = -1;
// find the changed axis
for ( int row = 0; row < numRows(); row++ )
{
for ( int col = 0; col < numColumns(); col++ )
{
QwtPlot* p = plotAt( row, col );
if ( p )
{
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
{
if ( p->axisWidget( axisPos ) == sender() )
{
plt = p;
axisId = axisPos;
rowOrColumn = QwtAxis::isXAxis( axisId ) ? col : row;
}
}
}
}
}
if ( plt )
{
const QwtScaleDiv scaleDiv = plt->axisScaleDiv( axisId );
// synchronize the axes
if ( QwtAxis::isXAxis( axisId ) )
{
for ( int row = 0; row < numRows(); row++ )
{
QwtPlot* p = plotAt( row, rowOrColumn );
if ( p != plt )
{
p->setAxisScaleDiv( axisId, scaleDiv );
}
}
}
else
{
for ( int col = 0; col < numColumns(); col++ )
{
QwtPlot* p = plotAt( rowOrColumn, col );
if ( p != plt )
{
p->setAxisScaleDiv( axisId, scaleDiv );
}
}
}
updateLayout();
}
m_data->inScaleSync = false;
}
void PlotMatrix::updateLayout()
{
using namespace QwtAxis;
for ( int row = 0; row < numRows(); row++ )
{
for ( int col = 0; col < numColumns(); col++ )
{
QwtPlot* p = plotAt( row, col );
if ( p )
{
bool showAxis[AxisPositions];
showAxis[XBottom] = isAxisVisible( XBottom ) && row == numRows() - 1;
showAxis[XTop] = isAxisVisible( XTop ) && row == 0;
showAxis[YLeft] = isAxisVisible( YLeft ) && col == 0;
showAxis[YRight] = isAxisVisible( YRight ) && col == numColumns() - 1;
for ( int axis = 0; axis < AxisPositions; axis++ )
{
enablePlotAxis( p, axis, showAxis[axis] );
}
}
}
}
for ( int row = 0; row < numRows(); row++ )
{
alignAxes( row, XTop );
alignAxes( row, XBottom );
alignScaleBorder( row, YLeft );
alignScaleBorder( row, YRight );
}
for ( int col = 0; col < numColumns(); col++ )
{
alignAxes( col, YLeft );
alignAxes( col, YRight );
alignScaleBorder( col, XBottom );
alignScaleBorder( col, XTop );
}
for ( int row = 0; row < numRows(); row++ )
{
for ( int col = 0; col < numColumns(); col++ )
{
QwtPlot* p = plotAt( row, col );
if ( p )
p->replot();
}
}
}
void PlotMatrix::alignAxes( int rowOrColumn, int axis )
{
if ( QwtAxis::isYAxis( axis ) )
{
double maxExtent = 0;
for ( int row = 0; row < numRows(); row++ )
{
QwtPlot* p = plotAt( row, rowOrColumn );
if ( p )
{
QwtScaleWidget* scaleWidget = p->axisWidget( axis );
QwtScaleDraw* sd = scaleWidget->scaleDraw();
sd->setMinimumExtent( 0.0 );
const double extent = sd->extent( scaleWidget->font() );
if ( extent > maxExtent )
maxExtent = extent;
}
}
for ( int row = 0; row < numRows(); row++ )
{
QwtPlot* p = plotAt( row, rowOrColumn );
if ( p )
{
QwtScaleWidget* scaleWidget = p->axisWidget( axis );
scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
}
}
}
else
{
double maxExtent = 0;
for ( int col = 0; col < numColumns(); col++ )
{
QwtPlot* p = plotAt( rowOrColumn, col );
if ( p )
{
QwtScaleWidget* scaleWidget = p->axisWidget( axis );
QwtScaleDraw* sd = scaleWidget->scaleDraw();
sd->setMinimumExtent( 0.0 );
const double extent = sd->extent( scaleWidget->font() );
if ( extent > maxExtent )
maxExtent = extent;
}
}
for ( int col = 0; col < numColumns(); col++ )
{
QwtPlot* p = plotAt( rowOrColumn, col );
if ( p )
{
QwtScaleWidget* scaleWidget = p->axisWidget( axis );
scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
}
}
}
}
void PlotMatrix::alignScaleBorder( int rowOrColumn, int axis )
{
int startDist = 0;
int endDist = 0;
if ( axis == QwtAxis::YLeft )
{
QwtPlot* plot = plotAt( rowOrColumn, 0 );
if ( plot )
plot->axisWidget( axis )->getBorderDistHint( startDist, endDist );
for ( int col = 1; col < numColumns(); col++ )
{
plot = plotAt( rowOrColumn, col );
if ( plot )
plot->axisWidget( axis )->setMinBorderDist( startDist, endDist );
}
}
else if ( axis == QwtAxis::YRight )
{
QwtPlot* plot = plotAt( rowOrColumn, numColumns() - 1 );
if ( plot )
plot->axisWidget( axis )->getBorderDistHint( startDist, endDist );
for ( int col = 0; col < numColumns() - 1; col++ )
{
plot = plotAt( rowOrColumn, col );
if ( plot )
plot->axisWidget( axis )->setMinBorderDist( startDist, endDist );
}
}
if ( axis == QwtAxis::XTop )
{
QwtPlot* plot = plotAt( rowOrColumn, 0 );
if ( plot )
plot->axisWidget( axis )->getBorderDistHint( startDist, endDist );
for ( int row = 1; row < numRows(); row++ )
{
plot = plotAt( row, rowOrColumn );
if ( plot )
plot->axisWidget( axis )->setMinBorderDist( startDist, endDist );
}
}
else if ( axis == QwtAxis::XBottom )
{
QwtPlot* plot = plotAt( numRows() - 1, rowOrColumn );
if ( plot )
plot->axisWidget( axis )->getBorderDistHint( startDist, endDist );
for ( int row = 0; row < numRows() - 1; row++ )
{
plot = plotAt( row, rowOrColumn );
if ( plot )
plot->axisWidget( axis )->setMinBorderDist( startDist, endDist );
}
}
}
#include "moc_PlotMatrix.cpp"

View File

@@ -0,0 +1,44 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include <QFrame>
class QwtPlot;
class PlotMatrix : public QFrame
{
Q_OBJECT
public:
PlotMatrix( int rows, int columns, QWidget* parent = NULL );
virtual ~PlotMatrix();
int numRows() const;
int numColumns() const;
QwtPlot* plotAt( int row, int column );
const QwtPlot* plotAt( int row, int column ) const;
void setAxisVisible( int axisId, bool tf = true );
bool isAxisVisible( int axisId ) const;
void setAxisScale( int axisId, int rowOrColumn,
double min, double max, double step = 0 );
protected:
void updateLayout();
private Q_SLOTS:
void scaleDivChanged();
private:
void alignAxes( int rowOrColumn, int axis );
void alignScaleBorder( int rowOrColumn, int axis );
class PrivateData;
PrivateData* m_data;
};

View File

@@ -0,0 +1,80 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "PlotMatrix.h"
#include <QwtPlotGrid>
#include <QwtPlot>
#include <QwtScaleWidget>
#include <QwtMath>
#include <QApplication>
namespace
{
class MainWindow : public PlotMatrix
{
public:
MainWindow();
};
}
MainWindow::MainWindow()
: PlotMatrix( 3, 4 )
{
using namespace QwtAxis;
setAxisVisible( YLeft );
setAxisVisible( YRight );
setAxisVisible( XBottom );
for ( int row = 0; row < numRows(); row++ )
{
const double v = std::pow( 10.0, row );
setAxisScale( YLeft, row, -v, v );
setAxisScale( YRight, row, -v, v );
}
for ( int col = 0; col < numColumns(); col++ )
{
const double v = std::pow( 10.0, col );
setAxisScale( XBottom, col, -v, v );
setAxisScale( XTop, col, -v, v );
}
for ( int row = 0; row < numRows(); row++ )
{
for ( int col = 0; col < numColumns(); col++ )
{
QwtPlot* plot = plotAt( row, col );
plot->setCanvasBackground( QColor( Qt::darkGray ) );
QwtPlotGrid* grid = new QwtPlotGrid();
grid->enableXMin( true );
grid->setMajorPen( Qt::white, 0, Qt::DotLine );
grid->setMinorPen( Qt::gray, 0, Qt::DotLine );
grid->attach( plot );
}
}
plotAt( 1, 0 )->axisWidget( YLeft )->setLabelRotation( 45 );
plotAt( 1, numColumns() - 1 )->axisWidget( YRight )->setLabelRotation( -45 );
updateLayout();
}
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,15 @@
######################################################################
# 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 = plotmatrix
HEADERS = \
PlotMatrix.h
SOURCES = \
PlotMatrix.cpp \
main.cpp

View File

@@ -0,0 +1,153 @@
/*****************************************************************************
* 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 <QwtPlot>
#include <QwtPlotRescaler>
#include <QwtInterval>
#include <QGroupBox>
#include <QComboBox>
#include <QLayout>
#include <QStatusBar>
#include <QLabel>
MainWindow::MainWindow()
{
QFrame* w = new QFrame( this );
QWidget* panel = createPanel( w );
panel->setFixedWidth( 2 * panel->sizeHint().width() );
m_plot = createPlot( w );
QHBoxLayout* layout = new QHBoxLayout( w );
layout->setContentsMargins( QMargins() );
layout->addWidget( panel, 0 );
layout->addWidget( m_plot, 10 );
setCentralWidget( w );
setRescaleMode( 0 );
( void )statusBar();
}
QWidget* MainWindow::createPanel( QWidget* parent )
{
QGroupBox* panel = new QGroupBox( "Navigation Panel", parent );
QComboBox* rescaleBox = new QComboBox( panel );
rescaleBox->setEditable( false );
rescaleBox->insertItem( KeepScales, "None" );
rescaleBox->insertItem( Fixed, "Fixed" );
rescaleBox->insertItem( Expanding, "Expanding" );
rescaleBox->insertItem( Fitting, "Fitting" );
connect( rescaleBox, SIGNAL(activated(int)), SLOT(setRescaleMode(int)) );
m_rescaleInfo = new QLabel( panel );
m_rescaleInfo->setSizePolicy(
QSizePolicy::Expanding, QSizePolicy::Expanding );
m_rescaleInfo->setWordWrap( true );
QVBoxLayout* layout = new QVBoxLayout( panel );
layout->addWidget( rescaleBox );
layout->addWidget( m_rescaleInfo );
layout->addStretch( 10 );
return panel;
}
Plot* MainWindow::createPlot( QWidget* parent )
{
Plot* plot = new Plot( parent, QwtInterval( 0.0, 1000.0 ) );
plot->replot();
m_rescaler = new QwtPlotRescaler( plot->canvas() );
m_rescaler->setReferenceAxis( QwtAxis::XBottom );
m_rescaler->setAspectRatio( QwtAxis::YLeft, 1.0 );
m_rescaler->setAspectRatio( QwtAxis::YRight, 0.0 );
m_rescaler->setAspectRatio( QwtAxis::XTop, 0.0 );
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
m_rescaler->setIntervalHint( axisPos, QwtInterval( 0.0, 1000.0 ) );
connect( plot, SIGNAL(resized(double,double)),
SLOT(showRatio(double,double)) );
return plot;
}
void MainWindow::setRescaleMode( int mode )
{
bool doEnable = true;
QString info;
QRectF rectOfInterest;
QwtPlotRescaler::ExpandingDirection direction = QwtPlotRescaler::ExpandUp;
switch( mode )
{
case KeepScales:
{
doEnable = false;
info = "All scales remain unchanged, when the plot is resized";
break;
}
case Fixed:
{
m_rescaler->setRescalePolicy( QwtPlotRescaler::Fixed );
info = "The scale of the bottom axis remains unchanged, "
"when the plot is resized. All other scales are changed, "
"so that a pixel on screen means the same distance for"
"all scales.";
break;
}
case Expanding:
{
m_rescaler->setRescalePolicy( QwtPlotRescaler::Expanding );
info = "The scales of all axis are shrinked/expanded, when "
"resizing the plot, keeping the distance that is represented "
"by one pixel.";
m_rescaleInfo->setText( "Expanding" );
break;
}
case Fitting:
{
m_rescaler->setRescalePolicy( QwtPlotRescaler::Fitting );
const QwtInterval xIntv =
m_rescaler->intervalHint( QwtAxis::XBottom );
const QwtInterval yIntv =
m_rescaler->intervalHint( QwtAxis::YLeft );
rectOfInterest = QRectF( xIntv.minValue(), yIntv.minValue(),
xIntv.width(), yIntv.width() );
direction = QwtPlotRescaler::ExpandBoth;
info = "Fitting";
break;
}
}
m_plot->setRectOfInterest( rectOfInterest );
m_rescaleInfo->setText( info );
m_rescaler->setEnabled( doEnable );
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
m_rescaler->setExpandingDirection( direction );
if ( doEnable )
m_rescaler->rescale();
else
m_plot->replot();
}
void MainWindow::showRatio( double xRatio, double yRatio )
{
const QString msg = QString( "%1, %2" ).arg( xRatio ).arg( yRatio );
statusBar()->showMessage( msg );
}
#include "moc_MainWindow.cpp"

View File

@@ -0,0 +1,41 @@
/*****************************************************************************
* 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 QwtPlotRescaler;
class QLabel;
class Plot;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
enum RescaleMode
{
KeepScales,
Fixed,
Expanding,
Fitting
};
MainWindow();
private Q_SLOTS:
void setRescaleMode( int );
void showRatio( double, double );
private:
QWidget* createPanel( QWidget* );
Plot* createPlot( QWidget* );
QwtPlotRescaler* m_rescaler;
QLabel* m_rescaleInfo;
Plot* m_plot;
};

View File

@@ -0,0 +1,190 @@
/*****************************************************************************
* 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 <QwtPlotGrid>
#include <QwtPlotItem>
#include <QwtScaleMap>
#include <QwtPlotLayout>
#include <QwtInterval>
#include <QwtPainter>
#include <QwtMath>
#include <QPainter>
class TextItem : public QwtPlotItem
{
public:
void setText( const QString& text )
{
m_text = text;
}
virtual void draw( QPainter* painter,
const QwtScaleMap&, const QwtScaleMap&,
const QRectF& canvasRect ) const QWT_OVERRIDE
{
const int margin = 5;
const QRectF textRect =
canvasRect.adjusted( margin, margin, -margin, -margin );
painter->setPen( Qt::white );
painter->drawText( textRect,
Qt::AlignBottom | Qt::AlignRight, m_text );
}
private:
QString m_text;
};
// RectItem shows how to implement a simple plot item,
// what wouldn't be necessary as QwtPlotShapeItem
// would do the same
class RectItem : public QwtPlotItem
{
public:
enum Type
{
Rect,
Ellipse
};
explicit RectItem( Type type )
: m_type( type )
{
}
void setPen( const QPen& pen )
{
if ( pen != m_pen )
{
m_pen = pen;
itemChanged();
}
}
void setBrush( const QBrush& brush )
{
if ( brush != m_brush )
{
m_brush = brush;
itemChanged();
}
}
void setRect( const QRectF& rect )
{
if ( m_rect != rect )
{
m_rect = rect;
itemChanged();
}
}
virtual QRectF boundingRect() const QWT_OVERRIDE
{
return m_rect;
}
virtual void draw( QPainter* painter,
const QwtScaleMap& xMap, const QwtScaleMap& yMap,
const QRectF& ) const QWT_OVERRIDE
{
if ( m_rect.isValid() )
{
const QRectF rect = QwtScaleMap::transform(
xMap, yMap, m_rect );
painter->setPen( m_pen );
painter->setBrush( m_brush );
if ( m_type == Ellipse )
QwtPainter::drawEllipse( painter, rect );
else
QwtPainter::drawRect( painter, rect );
}
}
private:
QPen m_pen;
QBrush m_brush;
QRectF m_rect;
Type m_type;
};
Plot::Plot( QWidget* parent, const QwtInterval& interval )
: QwtPlot( parent )
{
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
setAxisScale( axisPos, interval.minValue(), interval.maxValue() );
setCanvasBackground( QColor( Qt::darkBlue ) );
plotLayout()->setAlignCanvasToScales( true );
// 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 );
const int numEllipses = 10;
for ( int i = 0; i < numEllipses; i++ )
{
const double x = interval.minValue() +
qwtRand() % qRound( interval.width() );
const double y = interval.minValue() +
qwtRand() % qRound( interval.width() );
const double r = interval.minValue() +
qwtRand() % qRound( interval.width() / 6 );
const QRectF area( x - r, y - r, 2 * r, 2 * r );
RectItem* item = new RectItem( RectItem::Ellipse );
item->setRenderHint( QwtPlotItem::RenderAntialiased, true );
item->setRect( area );
item->setPen( QPen( Qt::yellow ) );
item->attach( this );
}
TextItem* textItem = new TextItem();
textItem->setText( "Navigation Example" );
textItem->attach( this );
m_rectItem = new RectItem( RectItem::Rect );
m_rectItem->setPen( Qt::NoPen );
QColor c = Qt::gray;
c.setAlpha( 100 );
m_rectItem->setBrush( QBrush( c ) );
m_rectItem->attach( this );
}
void Plot::updateLayout()
{
QwtPlot::updateLayout();
const QwtScaleMap xMap = canvasMap( QwtAxis::XBottom );
const QwtScaleMap yMap = canvasMap( QwtAxis::YLeft );
const QRect cr = canvas()->contentsRect();
const double x1 = xMap.invTransform( cr.left() );
const double x2 = xMap.invTransform( cr.right() );
const double y1 = yMap.invTransform( cr.bottom() );
const double y2 = yMap.invTransform( cr.top() );
const double xRatio = ( x2 - x1 ) / cr.width();
const double yRatio = ( y2 - y1 ) / cr.height();
Q_EMIT resized( xRatio, yRatio );
}
void Plot::setRectOfInterest( const QRectF& rect )
{
m_rectItem->setRect( rect );
}
#include "moc_Plot.cpp"

View File

@@ -0,0 +1,28 @@
/*****************************************************************************
* 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 RectItem;
class QwtInterval;
class Plot : public QwtPlot
{
Q_OBJECT
public:
Plot( QWidget* parent, const QwtInterval& );
virtual void updateLayout() QWT_OVERRIDE;
void setRectOfInterest( const QRectF& );
Q_SIGNALS:
void resized( double xRatio, double yRatio );
private:
RectItem* m_rectItem;
};

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 "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,18 @@
######################################################################
# 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 = rescaler
HEADERS = \
MainWindow.h \
Plot.h
SOURCES = \
MainWindow.cpp \
Plot.cpp \
main.cpp

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

109
playground/shapes/main.cpp Normal file
View File

@@ -0,0 +1,109 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include <QwtPlot>
#include <QwtLegend>
#include <QwtPlotPanner>
#include <QwtPlotMagnifier>
#include <QwtPlotShapeItem>
#include <QApplication>
#include <QPainterPath>
namespace
{
class ShapeItem : public QwtPlotShapeItem
{
public:
ShapeItem()
: QwtPlotShapeItem( "Shape" )
{
setRenderHint( QwtPlotItem::RenderAntialiased, true );
setRenderTolerance( 1.0 );
setPen( Qt::yellow );
QColor c = Qt::darkRed;
c.setAlpha( 100 );
setBrush( c );
setShape( demoShape() );
}
private:
static QPainterPath demoShape()
{
const double d = 900.0;
const QRectF rect( 1.0, 1.0, d, d );
QPainterPath path;
//path.setFillRule( Qt::WindingFill );
path.addEllipse( rect );
const QRectF rect2 = rect.adjusted( 0.2 * d, 0.3 * d, -0.22 * d, 1.5 * d );
path.addEllipse( rect2 );
#if 0
QFont font;
font.setPointSizeF( 200 );
QPainterPath textPath;
textPath.addText( rect.center(), font, "Shape" );
QTransform transform;
transform.translate( rect.center().x() - 600, rect.center().y() + 50 );
transform.rotate( 180.0, Qt::XAxis );
textPath = transform.map( textPath );
path.addPath( textPath );
#endif
return path;
}
};
class Plot : public QwtPlot
{
public:
Plot()
{
setPalette( QColor( 60, 60, 60 ) );
canvas()->setPalette( Qt::white );
// panning with the left mouse button
( void ) new QwtPlotPanner( canvas() );
// zoom in/out with the wheel
( void ) new QwtPlotMagnifier( canvas() );
setTitle( "Shapes" );
insertLegend( new QwtLegend(), QwtPlot::RightLegend );
// axes
using namespace QwtAxis;
setAxisTitle( XBottom, "x -->" );
setAxisTitle( YLeft, "y -->" );
#if 0
setAxisScaleEngine( XBottom, new QwtLog10ScaleEngine );
setAxisScaleEngine( YLeft, new QwtLog10ScaleEngine );
#endif
ShapeItem* item = new ShapeItem();
item->setItemAttribute( QwtPlotItem::Legend, true );
item->attach( this );
}
};
}
int main( int argc, char* argv[] )
{
QApplication app( argc, argv );
Plot plot;
plot.resize( 600, 400 );
plot.show();
return app.exec();
}

View File

@@ -0,0 +1,12 @@
######################################################################
# 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 = shapes
SOURCES = \
main.cpp

103
playground/svgmap/Plot.cpp Normal file
View File

@@ -0,0 +1,103 @@
/*****************************************************************************
* 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 <QwtPlotGraphicItem>
#include <QwtPlotLayout>
#include <QwtPlotPanner>
#include <QwtPlotMagnifier>
#include <QwtGraphic>
#define DEBUG_SCALE 0
#if DEBUG_SCALE
#include <QwtPlotGrid>
#endif
#include <QSvgRenderer>
#include <QFileDialog>
Plot::Plot( QWidget* parent )
: QwtPlot( parent )
, m_mapItem( NULL )
, m_mapRect( 0.0, 0.0, 100.0, 100.0 ) // something
{
#if DEBUG_SCALE
QwtPlotGrid* grid = new QwtPlotGrid();
grid->attach( this );
#else
/*
m_mapRect is only a reference for zooming, but
the ranges are nothing useful for the user. So we
hide the axes.
*/
plotLayout()->setCanvasMargin( 0 );
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
setAxisVisible( axisPos, false );
#endif
/*
Navigation:
Left Mouse Button: Panning
Mouse Wheel: Zooming In/Out
Right Mouse Button: Reset to initial
*/
( void )new QwtPlotPanner( canvas() );
( void )new QwtPlotMagnifier( canvas() );
canvas()->setFocusPolicy( Qt::WheelFocus );
setCanvasBackground( Qt::white );
rescale();
}
#ifndef QT_NO_FILEDIALOG
void Plot::loadSVG()
{
QString dir;
const QString fileName = QFileDialog::getOpenFileName( NULL,
"Load a Scaleable Vector Graphic (SVG) Map",
dir, "SVG Files (*.svg)" );
if ( !fileName.isEmpty() )
loadSVG( fileName );
}
#endif
void Plot::loadSVG( const QString& fileName )
{
if ( m_mapItem == NULL )
{
m_mapItem = new QwtPlotGraphicItem();
m_mapItem->attach( this );
}
QwtGraphic graphic;
QSvgRenderer renderer;
if ( renderer.load( fileName ) )
{
QPainter p( &graphic );
renderer.render( &p );
}
m_mapItem->setGraphic( m_mapRect, graphic );
rescale();
replot();
}
void Plot::rescale()
{
setAxisScale( QwtAxis::XBottom, m_mapRect.left(), m_mapRect.right() );
setAxisScale( QwtAxis::YLeft, m_mapRect.top(), m_mapRect.bottom() );
}
#include "moc_Plot.cpp"

33
playground/svgmap/Plot.h Normal file
View File

@@ -0,0 +1,33 @@
/*****************************************************************************
* 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>
#include <QRect>
class QwtPlotGraphicItem;
class Plot : public QwtPlot
{
Q_OBJECT
public:
Plot( QWidget* = NULL );
public Q_SLOTS:
#ifndef QT_NO_FILEDIALOG
void loadSVG();
#endif
void loadSVG( const QString& );
private:
void rescale();
QwtPlotGraphicItem* m_mapItem;
const QRectF m_mapRect;
};

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 92 KiB

View File

@@ -0,0 +1,65 @@
/*****************************************************************************
* 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 <QApplication>
#include <QMainWindow>
#ifndef QT_NO_FILEDIALOG
#include <QToolBar>
#include <QToolButton>
#endif
namespace
{
class MainWindow : public QMainWindow
{
public:
MainWindow( const QString& fileName )
{
Plot* plot = new Plot( this );
if ( !fileName.isEmpty() )
plot->loadSVG( fileName );
setCentralWidget( plot );
#ifndef QT_NO_FILEDIALOG
QToolButton* btnLoad = new QToolButton();
btnLoad->setText( "Load SVG" );
btnLoad->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
QToolBar* toolBar = new QToolBar();
toolBar->addWidget( btnLoad );
addToolBar( toolBar );
connect( btnLoad, SIGNAL(clicked()), plot, SLOT(loadSVG()) );
#endif
}
};
}
int main( int argc, char* argv[] )
{
QApplication app( argc, argv );
QString fileName;
if ( argc > 1 )
{
fileName = argv[1];
}
else
{
// see: https://commons.wikimedia.org/wiki/File:Schlosspark_Nymphenburg.svg
fileName = ":/svg/Schlosspark_Nymphenburg.svg";
}
MainWindow window( fileName );
window.resize( 600, 600 );
window.show();
return app.exec();
}

View 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
######################################################################
include( $${PWD}/../playground.pri )
greaterThan(QT_MAJOR_VERSION, 4) {
!qtHaveModule(svg) {
error("Qt has been built without SVG support !")
}
}
TARGET = svgmap
QT += svg
RESOURCES += \
svgmap.qrc
HEADERS = \
Plot.h
SOURCES = \
Plot.cpp \
main.cpp

View File

@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/svg">
<file>Schlosspark_Nymphenburg.svg</file>
</qresource>
</RCC>

237
playground/symbols/main.cpp Normal file
View File

@@ -0,0 +1,237 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include <QwtPlot>
#include <QwtPlotCurve>
#include <QwtSymbol>
#include <QwtGraphic>
#include <QwtLegend>
#include <QwtMath>
#include <QApplication>
#include <QPainter>
#include <QPainterPath>
#include <QBuffer>
#include <qmath.h>
#ifdef QT_SVG_LIB
#include <QSvgGenerator>
#endif
class MySymbol : public QwtSymbol
{
public:
MySymbol( QwtSymbol::Style style, const QBrush& brush )
{
QPen pen( Qt::black, 0 );
pen.setJoinStyle( Qt::MiterJoin );
pen.setCosmetic( true );
QPainterPath path = createArrow( QSize( 16, 24 ) );
const QSizeF pathSize = path.boundingRect().size();
setSize( 0.8 * pathSize.toSize() );
setPinPoint( QPointF( 0.0, 0.0 ) );
switch( style )
{
case QwtSymbol::Pixmap:
{
const QSize sz = size();
const double ratio = qMin( sz.width() / pathSize.width(),
sz.height() / pathSize.height() );
QTransform transform;
transform.scale( ratio, ratio );
path = transform.map( path );
if ( isPinPointEnabled() )
{
QPointF pos = transform.map( pinPoint() );
setPinPoint( pos );
}
const QRectF br = path.boundingRect();
int m = 2 + qCeil( pen.widthF() );
QPixmap pm( sz + QSize( 2 * m, 2 * m ) );
pm.fill( Qt::transparent );
QPainter painter( &pm );
painter.setRenderHint( QPainter::Antialiasing, true );
painter.setPen( pen );
painter.setBrush( brush );
painter.translate( m, m );
painter.translate( -br.left(), br.top() );
painter.drawPath( path );
setPixmap( pm );
setSize( pm.size() );
if ( isPinPointEnabled() )
setPinPoint( pinPoint() + QPointF( m, m ) );
break;
}
case QwtSymbol::Graphic:
{
QwtGraphic graphic;
graphic.setRenderHint( QwtGraphic::RenderPensUnscaled );
QPainter painter( &graphic );
painter.setRenderHint( QPainter::Antialiasing, true );
painter.setPen( pen );
painter.setBrush( brush );
painter.drawPath( path );
painter.end();
setGraphic( graphic );
break;
}
case QwtSymbol::SvgDocument:
{
#ifndef QWT_NO_SVG
QBuffer buf;
QSvgGenerator generator;
generator.setOutputDevice( &buf );
QPainter painter( &generator );
painter.setRenderHint( QPainter::Antialiasing, true );
painter.setPen( pen );
painter.setBrush( brush );
painter.drawPath( path );
painter.end();
setSvgDocument( buf.data() );
#endif
break;
}
case QwtSymbol::Path:
default:
{
setPen( pen );
setBrush( brush );
setPath( path );
}
}
}
private:
QPainterPath createArrow( const QSizeF& size ) const
{
const double w = size.width();
const double h = size.height();
const double y0 = 0.6 * h;
QPainterPath path;
path.moveTo( -0.2 * w, h );
path.lineTo( 0.2 * w, h );
path.moveTo( 0, h );
path.lineTo( 0, y0 );
path.lineTo( -0.5 * w, y0 );
path.lineTo( 0, 0 );
path.lineTo( 0.5 * w, y0 );
path.lineTo( 0, y0 );
QTransform transform;
transform.rotate( -30.0 );
path = transform.map( path );
return path;
}
};
class Plot : public QwtPlot
{
public:
Plot()
{
setTitle( "Plot Demo" );
setCanvasBackground( Qt::white );
setAxisScale( QwtAxis::XBottom, -1.0, 6.0 );
QwtLegend* legend = new QwtLegend();
insertLegend( legend );
populate();
}
void populate()
{
for ( int i = 0; i < 4; i++ )
{
QwtPlotCurve* curve = new QwtPlotCurve();
curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
curve->setPen( Qt::blue );
QBrush brush;
QwtSymbol::Style style = QwtSymbol::NoSymbol;
QString title;
if ( i == 0 )
{
brush = Qt::magenta;
style = QwtSymbol::Path;
title = "Path";
}
else if ( i == 2 )
{
brush = Qt::red;
style = QwtSymbol::Graphic;
title = "Graphic";
}
else if ( i == 1 )
{
brush = Qt::yellow;
style = QwtSymbol::SvgDocument;
title = "Svg";
}
else if ( i == 3 )
{
brush = Qt::cyan;
style = QwtSymbol::Pixmap;
title = "Pixmap";
}
MySymbol* symbol = new MySymbol( style, brush );
curve->setSymbol( symbol );
curve->setTitle( title );
curve->setLegendAttribute( QwtPlotCurve::LegendShowSymbol, true );
curve->setLegendIconSize( QSize( 15, 18 ) );
QPolygonF points;
points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
<< QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
<< QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
points.translate( 0.0, i * 2.0 );
curve->setSamples( points );
curve->attach( this );
}
}
};
int main( int argc, char* argv[] )
{
QApplication app( argc, argv );
Plot plot;
plot.resize( 600, 400 );
plot.show();
return app.exec();
}

View File

@@ -0,0 +1,12 @@
######################################################################
# 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 = symbols
SOURCES = \
main.cpp

View File

@@ -0,0 +1,67 @@
/*****************************************************************************
* 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 "Panel.h"
#include <QwtDate>
#include <QwtScaleWidget>
#include <QLayout>
MainWindow::MainWindow( QWidget* parent )
: QMainWindow( parent )
{
Settings settings;
#if 1
settings.startDateTime = QDateTime( QDate( 2012, 10, 27 ), QTime( 18, 5, 0, 0 ) );
settings.endDateTime = QDateTime( QDate( 2012, 10, 28 ), QTime( 12, 12, 0, 0 ) );
#else
settings.startDateTime = QDateTime( QDate( 2011, 5, 3 ), QTime( 0, 6, 0, 0 ) );
settings.endDateTime = QDateTime( QDate( 2012, 3, 10 ), QTime( 0, 5, 0, 0 ) );
#endif
settings.maxMajorSteps = 10;
settings.maxMinorSteps = 8;
settings.maxWeeks = -1;
m_plot = new Plot();
m_panel = new Panel();
m_panel->setSettings( settings );
QWidget* box = new QWidget( this );
QHBoxLayout* layout = new QHBoxLayout( box );
layout->addWidget( m_plot, 10 );
layout->addWidget( m_panel );
setCentralWidget( box );
updatePlot();
connect( m_panel, SIGNAL(edited()), SLOT(updatePlot()) );
connect( m_plot->axisWidget( QwtAxis::YLeft ),
SIGNAL(scaleDivChanged()), SLOT(updatePanel()) );
}
void MainWindow::updatePlot()
{
m_plot->blockSignals( true );
m_plot->applySettings( m_panel->settings() );
m_plot->blockSignals( false );
}
void MainWindow::updatePanel()
{
const QwtScaleDiv scaleDiv = m_plot->axisScaleDiv( QwtAxis::YLeft );
Settings settings = m_panel->settings();
settings.startDateTime = QwtDate::toDateTime( scaleDiv.lowerBound(), Qt::LocalTime );
settings.endDateTime = QwtDate::toDateTime( scaleDiv.upperBound(), Qt::LocalTime );
m_panel->setSettings( settings );
}
#include "moc_MainWindow.cpp"

View File

@@ -0,0 +1,27 @@
/*****************************************************************************
* 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 Panel;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget* parent = 0 );
private Q_SLOTS:
void updatePlot();
void updatePanel();
private:
Plot* m_plot;
Panel* m_panel;
};

View File

@@ -0,0 +1,102 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "Panel.h"
#include "Settings.h"
#include <QDateTimeEdit>
#include <QSpinBox>
#include <QLayout>
#include <QLabel>
Panel::Panel( QWidget* parent )
: QWidget( parent )
{
// create widgets
m_startDateTime = new QDateTimeEdit();
m_startDateTime->setDisplayFormat( "M/d/yyyy h:mm AP :zzz" );
m_startDateTime->setCalendarPopup( true );
m_endDateTime = new QDateTimeEdit();
m_endDateTime->setDisplayFormat( "M/d/yyyy h:mm AP :zzz" );
m_endDateTime->setCalendarPopup( true );
m_maxMajorSteps = new QSpinBox();
m_maxMajorSteps->setRange( 0, 50 );
m_maxMinorSteps = new QSpinBox();
m_maxMinorSteps->setRange( 0, 50 );
m_maxWeeks = new QSpinBox();
m_maxWeeks->setRange( -1, 100 );
m_maxWeeks->setSpecialValueText( "Disabled" );
// layout
QGridLayout* layout = new QGridLayout( this );
layout->setAlignment( Qt::AlignLeft | Qt::AlignTop );
int row = 0;
layout->addWidget( new QLabel( "From" ), row, 0 );
layout->addWidget( m_startDateTime, row, 1 );
row++;
layout->addWidget( new QLabel( "To" ), row, 0 );
layout->addWidget( m_endDateTime, row, 1 );
row++;
layout->addWidget( new QLabel( "Max. Major Steps" ), row, 0 );
layout->addWidget( m_maxMajorSteps, row, 1 );
row++;
layout->addWidget( new QLabel( "Max. Minor Steps" ), row, 0 );
layout->addWidget( m_maxMinorSteps, row, 1 );
row++;
layout->addWidget( new QLabel( "Max Weeks" ), row, 0 );
layout->addWidget( m_maxWeeks, row, 1 );
connect( m_startDateTime,
SIGNAL(dateTimeChanged(const QDateTime&)), SIGNAL(edited()) );
connect( m_endDateTime,
SIGNAL(dateTimeChanged(const QDateTime&)), SIGNAL(edited()) );
connect( m_maxMajorSteps,
SIGNAL(valueChanged(int)), SIGNAL(edited()) );
connect( m_maxMinorSteps,
SIGNAL(valueChanged(int)), SIGNAL(edited()) );
connect( m_maxWeeks,
SIGNAL(valueChanged(int)), SIGNAL(edited()) );
}
void Panel::setSettings( const Settings& settings )
{
blockSignals( true );
m_startDateTime->setDateTime( settings.startDateTime );
m_endDateTime->setDateTime( settings.endDateTime );
m_maxMajorSteps->setValue( settings.maxMajorSteps );
m_maxMinorSteps->setValue( settings.maxMinorSteps );
m_maxWeeks->setValue( settings.maxWeeks );
blockSignals( false );
}
Settings Panel::settings() const
{
Settings settings;
settings.startDateTime = m_startDateTime->dateTime();
settings.endDateTime = m_endDateTime->dateTime();
settings.maxMajorSteps = m_maxMajorSteps->value();
settings.maxMinorSteps = m_maxMinorSteps->value();
settings.maxWeeks = m_maxWeeks->value();
return settings;
}
#include "moc_Panel.cpp"

View File

@@ -0,0 +1,34 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include "Settings.h"
#include <QWidget>
class QDateTimeEdit;
class QSpinBox;
class Panel : public QWidget
{
Q_OBJECT
public:
Panel( QWidget* parent = NULL );
void setSettings( const Settings&);
Settings settings() const;
Q_SIGNALS:
void edited();
private:
QDateTimeEdit* m_startDateTime;
QDateTimeEdit* m_endDateTime;
QSpinBox* m_maxMajorSteps;
QSpinBox* m_maxMinorSteps;
QSpinBox* m_maxWeeks;
};

View File

@@ -0,0 +1,97 @@
/*****************************************************************************
* 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 "Settings.h"
#include <QwtDate>
#include <QwtDateScaleDraw>
#include <QwtDateScaleEngine>
#include <QwtPlotPanner>
#include <QwtPlotMagnifier>
#include <QwtPlotGrid>
#include <QwtPlotLayout>
Plot::Plot( QWidget* parent )
: QwtPlot( parent )
{
setAutoFillBackground( true );
setPalette( Qt::darkGray );
setCanvasBackground( Qt::white );
plotLayout()->setAlignCanvasToScales( true );
initAxis( QwtAxis::YLeft, "Local Time", Qt::LocalTime );
initAxis( QwtAxis::YRight,
"Coordinated Universal Time ( UTC )", Qt::UTC );
QwtPlotPanner* panner = new QwtPlotPanner( canvas() );
QwtPlotMagnifier* magnifier = new QwtPlotMagnifier( canvas() );
for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ )
{
const bool on = QwtAxis::isYAxis( axis );
setAxisVisible( axis, on );
panner->setAxisEnabled( axis, on );
magnifier->setAxisEnabled( axis, on );
}
QwtPlotGrid* grid = new QwtPlotGrid();
grid->setMajorPen( Qt::black, 0, Qt::SolidLine );
grid->setMinorPen( Qt::gray, 0, Qt::SolidLine );
grid->enableX( false );
grid->enableXMin( false );
grid->enableY( true );
grid->enableYMin( true );
grid->attach( this );
}
void Plot::initAxis( int axis,
const QString& title, Qt::TimeSpec timeSpec )
{
setAxisTitle( axis, title );
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw( timeSpec );
QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine( timeSpec );
#if 0
if ( timeSpec == Qt::LocalTime )
{
scaleDraw->setTimeSpec( Qt::OffsetFromUTC );
scaleDraw->setUtcOffset( 10 );
scaleEngine->setTimeSpec( Qt::OffsetFromUTC );
scaleEngine->setUtcOffset( 10 );
}
#endif
setAxisScaleDraw( axis, scaleDraw );
setAxisScaleEngine( axis, scaleEngine );
}
void Plot::applySettings( const Settings& settings )
{
applyAxisSettings( QwtAxis::YLeft, settings );
applyAxisSettings( QwtAxis::YRight, settings );
replot();
}
void Plot::applyAxisSettings( int axis, const Settings& settings )
{
QwtDateScaleEngine* scaleEngine =
static_cast< QwtDateScaleEngine* >( axisScaleEngine( axis ) );
scaleEngine->setMaxWeeks( settings.maxWeeks );
setAxisMaxMinor( axis, settings.maxMinorSteps );
setAxisMaxMajor( axis, settings.maxMajorSteps );
setAxisScale( axis, QwtDate::toDouble( settings.startDateTime ),
QwtDate::toDouble( settings.endDateTime ) );
}
#include "moc_Plot.cpp"

View 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 Settings;
class Plot : public QwtPlot
{
Q_OBJECT
public:
Plot( QWidget* parent = NULL );
public Q_SLOTS:
void applySettings( const Settings& );
private:
void initAxis( int axis, const QString& title, Qt::TimeSpec );
void applyAxisSettings( int axis, const Settings& );
};

View File

@@ -0,0 +1,27 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include <QDateTime>
class Settings
{
public:
Settings()
: maxMajorSteps( 10 )
, maxMinorSteps( 5 )
, maxWeeks( -1 )
{
};
QDateTime startDateTime;
QDateTime endDateTime;
int maxMajorSteps;
int maxMinorSteps;
int maxWeeks;
};

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 = timescale
HEADERS = \
Panel.h \
Plot.h \
MainWindow.h
SOURCES = \
Panel.cpp \
Plot.cpp \
MainWindow.cpp \
main.cpp

View File

@@ -0,0 +1,120 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include <QwtPlot>
#include <QwtVectorFieldSample>
#include <QwtPlotVectorField>
#include <QwtVectorFieldArrow>
#include <QwtPlotGrid>
#include <QwtLegend>
#include <QwtColorMap>
#include <QApplication>
#include <QPen>
namespace
{
class VectorField : public QwtPlotVectorField
{
public:
VectorField()
: QwtPlotVectorField( "Vector Field" )
{
setRenderHint( QwtPlotItem::RenderAntialiased, true );
setLegendIconSize( QSize( 20, 10 ) );
setMagnitudeScaleFactor( 1.0 );
#if 0
// test solid arrow
setSymbol( new QwtVectorFieldArrow() );
setPen( Qt::NoPen );
setBrush( Qt::black );
setMagnitudeScaleFactor( 2 );
#endif
#if 1
// test color map
QwtLinearColorMap* cm = new QwtLinearColorMap();
cm->setColorInterval( Qt::yellow, Qt::blue );
cm->addColorStop( 0.5, Qt::red );
setColorMap( cm );
setMagnitudeMode( MagnitudeAsColor, true );
#endif
#if 1
setIndicatorOrigin( QwtPlotVectorField::OriginHead );
#else
setIndicatorOrigin( QwtPlotVectorField::OriginTail );
#endif
#if 0
setRasterSize( QSizeF( 20, 20 ) );
#endif
setSamples( samples() );
}
private:
QVector< QwtVectorFieldSample > samples() const
{
const int dim = 10;
QVector< QwtVectorFieldSample > samples;
for ( int x = -dim; x < dim; x++ )
{
for ( int y = -dim; y < dim; y++ )
{
samples += QwtVectorFieldSample( x, y, y, -x );
}
}
return samples;
}
};
class Plot : public QwtPlot
{
public:
Plot()
{
setTitle( "Vector Field" );
setCanvasBackground( Qt::white );
insertLegend( new QwtLegend() );
QwtPlotGrid* grid = new QwtPlotGrid();
grid->attach( this );
VectorField* fieldItem = new VectorField();
fieldItem->attach( this );
const QRectF r = fieldItem->boundingRect();
#if 1
setAxisScale( QwtAxis::XBottom, r.left() - 1.0, r.right() + 1.0 );
#else
setAxisScale( QwtAxis::XBottom, r.right() + 1.0, r.left() - 1.0 );
#endif
#if 1
setAxisScale( QwtAxis::YLeft, r.top() - 1.0, r.bottom() + 1.0 );
#else
setAxisScale( QwtAxis::YLeft, r.bottom() + 1.0, r.top() - 1.0 );
#endif
}
};
}
int main( int argc, char* argv[] )
{
QApplication app( argc, argv );
Plot plot;
plot.resize( 600, 400 );
plot.show();
return app.exec();
}

View File

@@ -0,0 +1,12 @@
######################################################################
# 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 = vectorfield
SOURCES = \
main.cpp