Released version 6.1.3

This commit is contained in:
Wodann 2018-08-02 11:01:31 -04:00
commit a94503cb82
1885 changed files with 276310 additions and 0 deletions

View file

@ -0,0 +1,129 @@
#include "curvetracker.h"
#include <qwt_picker_machine.h>
#include <qwt_series_data.h>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
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::null;
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,22 @@
#ifndef _CURVE_TRACKER_H_
#define _CURVE_TRACKER_H_
#include <qwt_plot_picker.h>
class QwtPlotCurve;
class CurveTracker: public QwtPlotPicker
{
public:
CurveTracker( QWidget * );
protected:
virtual QwtText trackerTextF( const QPointF & ) const;
virtual QRect trackerRect( const QFont & ) const;
private:
QString curveInfoAt( const QwtPlotCurve *, const QPointF & ) const;
QLineF curveLineAt( const QwtPlotCurve *, double x ) const;
};
#endif

View 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}/../playground.pri )
TARGET = curvetracker
HEADERS = \
curvetracker.h \
plot.h
SOURCES = \
curvetracker.cpp \
plot.cpp \
main.cpp

View file

@ -0,0 +1,13 @@
#include <qapplication.h>
#include "plot.h"
int main( int argc, char **argv )
{
QApplication a( argc, argv );
Plot plot;
plot.resize( 600, 400 );
plot.show();
return a.exec();
}

View file

@ -0,0 +1,107 @@
#include "plot.h"
#include "curvetracker.h"
#include <qwt_picker_machine.h>
#include <qwt_plot_layout.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_textlabel.h>
#include <qwt_plot_zoneitem.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_layout.h>
#include <qwt_scale_widget.h>
#include <qwt_symbol.h>
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 axis = 0; axis < QwtPlot::axisCnt; axis++ )
axisWidget( axis )->setMargin( 0 );
QwtPlotCanvas *canvas = new QwtPlotCanvas();
canvas->setAutoFillBackground( false );
canvas->setFrameStyle( QFrame::NoFrame );
setCanvas( canvas );
setAxisScale( QwtPlot::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 );
}

View file

@ -0,0 +1,21 @@
#ifndef _PLOT_H_
#define _PLOT_H_
#include <qwt_plot.h>
class QPolygonF;
class Plot: public QwtPlot
{
Q_OBJECT
public:
Plot( QWidget * = NULL );
private:
void insertCurve( const QString &title,
const QColor &, const QPolygonF & );
};
#endif

View file

@ -0,0 +1,72 @@
#include "canvas.h"
#include <qwt_graphic.h>
#include <qsvgrenderer.h>
Canvas::Canvas( Mode mode, QWidget *parent ):
QWidget( parent ),
d_mode( mode )
{
const int m = 10;
setContentsMargins( m, m, m, m );
if ( d_mode == Svg )
d_renderer = new QSvgRenderer( this );
else
d_graphic = new QwtGraphic();
}
Canvas::~Canvas()
{
if ( d_mode == VectorGraphic )
delete d_graphic;
}
void Canvas::setSvg( const QByteArray &data )
{
if ( d_mode == VectorGraphic )
{
d_graphic->reset();
QSvgRenderer renderer;
renderer.load( data );
QPainter p( d_graphic );
renderer.render( &p, renderer.viewBoxF() );
p.end();
}
else
{
d_renderer->load( data );
}
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 ( d_mode == Svg )
{
d_renderer->render( painter, rect );
}
else
{
d_graphic->render( painter, rect );
}
}

View file

@ -0,0 +1,33 @@
#include <qwidget.h>
class QByteArray;
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 * );
private:
void render( QPainter *, const QRect & ) const;
const Mode d_mode;
union
{
QSvgRenderer *d_renderer;
QwtGraphic *d_graphic;
};
};

View file

@ -0,0 +1,23 @@
################################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
################################################################
include( $${PWD}/../playground.pri )
TARGET = graphicscale
QT += svg
HEADERS = \
canvas.h \
mainwindow.h
SOURCES = \
canvas.cpp \
mainwindow.cpp \
main.cpp

View 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( 600, 400 );
w.show();
return a.exec();
}

View file

@ -0,0 +1,109 @@
#include "mainwindow.h"
#include "canvas.h"
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qfiledialog.h>
#include <qbuffer.h>
#include <qpainter.h>
#include <qsvggenerator.h>
#include <qstatusbar.h>
MainWindow::MainWindow()
{
QWidget *w = new QWidget( this );
d_canvas[0] = new Canvas( Canvas::Svg, this );
d_canvas[0]->setAutoFillBackground( true );
d_canvas[0]->setPalette( Qt::gray );
d_canvas[1] = new Canvas( Canvas::VectorGraphic, this );
d_canvas[1]->setAutoFillBackground( true );
d_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( d_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( d_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();
d_canvas[0]->setSvg( document );
d_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();
d_canvas[0]->setSvg( buf.data() );
d_canvas[1]->setSvg( buf.data() );
}

View file

@ -0,0 +1,22 @@
#include <qmainwindow.h>
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 *d_canvas[2];
};

70
playground/playground.pri Normal file
View file

@ -0,0 +1,70 @@
################################################################
# 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
###################################################################
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
!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
}
win32 {
contains(QWT_CONFIG, QwtDll) {
DEFINES += QT_DLL QWT_DLL
}
}

32
playground/playground.pro Normal file
View file

@ -0,0 +1,32 @@
################################################################
# 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}/../qwtconfig.pri )
TEMPLATE = subdirs
contains(QWT_CONFIG, QwtPlot) {
SUBDIRS += \
plotmatrix \
timescale \
scaleengine \
graphicscale \
rescaler \
shapes \
curvetracker \
symbols
contains(QWT_CONFIG, QwtSvg) {
SUBDIRS += \
svgmap
}
}

View file

@ -0,0 +1,66 @@
#include "plotmatrix.h"
#include <qwt_plot_grid.h>
#include <qwt_scale_widget.h>
#include <qapplication.h>
#include <qpen.h>
#include <qmath.h>
class MainWindow: public PlotMatrix
{
public:
MainWindow();
};
MainWindow::MainWindow():
PlotMatrix( 3, 4 )
{
enableAxis( QwtPlot::yLeft );
enableAxis( QwtPlot::yRight );
enableAxis( QwtPlot::xBottom );
for ( int row = 0; row < numRows(); row++ )
{
const double v = qPow( 10.0, row );
setAxisScale( QwtPlot::yLeft, row, -v, v );
setAxisScale( QwtPlot::yRight, row, -v, v );
}
for ( int col = 0; col < numColumns(); col++ )
{
const double v = qPow( 10.0, col );
setAxisScale( QwtPlot::xBottom, col, -v, v );
setAxisScale( QwtPlot::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( QwtPlot::yLeft )->setLabelRotation( 45 );
plotAt( 1, numColumns() - 1 )->axisWidget( QwtPlot::yRight )->setLabelRotation( -45 );
updateLayout();
}
int main( int argc, char **argv )
{
QApplication a( argc, argv );
MainWindow mainWindow;
mainWindow.resize( 800, 600 );
mainWindow.show();
return a.exec();
}

View file

@ -0,0 +1,428 @@
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* 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
*****************************************************************************/
// vim: expandtab
#include <qlayout.h>
#include <qpen.h>
#include <qwt_plot.h>
#include <qwt_plot_canvas.h>
#include <qwt_scale_widget.h>
#include <qwt_scale_draw.h>
#include "plotmatrix.h"
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->enableAxis( 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 );
}
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
{
return minimumSizeHint();
}
};
class PlotMatrix::PrivateData
{
public:
PrivateData():
inScaleSync( false )
{
isAxisEnabled[QwtPlot::xBottom] = true;
isAxisEnabled[QwtPlot::xTop] = false;
isAxisEnabled[QwtPlot::yLeft] = true;
isAxisEnabled[QwtPlot::yRight] = false;
}
bool isAxisEnabled[QwtPlot::axisCnt];
QVector<QwtPlot *> plotWidgets;
mutable bool inScaleSync;
};
PlotMatrix::PlotMatrix( int numRows, int numColumns, QWidget *parent ):
QFrame( parent )
{
d_data = new PrivateData();
d_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 axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
connect( plot->axisWidget( axis ),
SIGNAL( scaleDivChanged() ), SLOT( scaleDivChanged() ) );
}
d_data->plotWidgets[row * numColumns + col] = plot;
}
}
updateLayout();
}
PlotMatrix::~PlotMatrix()
{
delete d_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 < d_data->plotWidgets.size() )
return d_data->plotWidgets[index];
return NULL;
}
const QwtPlot* PlotMatrix::plotAt( int row, int column ) const
{
const int index = row * numColumns() + column;
if ( index < d_data->plotWidgets.size() )
return d_data->plotWidgets[index];
return NULL;
}
void PlotMatrix::enableAxis( int axis, bool tf )
{
if ( axis >= 0 && axis < QwtPlot::axisCnt )
{
if ( tf != d_data->isAxisEnabled[axis] )
{
d_data->isAxisEnabled[axis] = tf;
updateLayout();
}
}
}
bool PlotMatrix::axisEnabled( int axis ) const
{
if ( axis >= 0 && axis < QwtPlot::axisCnt )
return d_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 ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
col = rowOrColumn;
else
row = rowOrColumn;
QwtPlot *plt = plotAt( row, col );
if ( plt )
{
plt->setAxisScale( axis, min, max, step );
plt->updateAxes();
}
}
void PlotMatrix::scaleDivChanged()
{
if ( d_data->inScaleSync )
return;
d_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 axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
if ( p->axisWidget( axis ) == sender() )
{
plt = p;
axisId = axis;
if ( axisId == QwtPlot::xBottom || axisId == QwtPlot::xTop )
rowOrColumn = col;
else
rowOrColumn = row;
}
}
}
}
}
if ( plt )
{
const QwtScaleDiv scaleDiv = plt->axisScaleDiv( axisId );
// synchronize the axes
if ( axisId == QwtPlot::xBottom || axisId == QwtPlot::xTop )
{
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();
}
d_data->inScaleSync = false;
}
void PlotMatrix::updateLayout()
{
for ( int row = 0; row < numRows(); row++ )
{
for ( int col = 0; col < numColumns(); col++ )
{
QwtPlot *p = plotAt( row, col );
if ( p )
{
bool showAxis[QwtPlot::axisCnt];
showAxis[QwtPlot::xBottom] =
axisEnabled( QwtPlot::xBottom ) && row == numRows() - 1;
showAxis[QwtPlot::xTop] =
axisEnabled( QwtPlot::xTop ) && row == 0;
showAxis[QwtPlot::yLeft] =
axisEnabled( QwtPlot::yLeft ) && col == 0;
showAxis[QwtPlot::yRight] =
axisEnabled( QwtPlot::yRight ) && col == numColumns() - 1;
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
enablePlotAxis( p, axis, showAxis[axis] );
}
}
}
}
for ( int row = 0; row < numRows(); row++ )
{
alignAxes( row, QwtPlot::xTop );
alignAxes( row, QwtPlot::xBottom );
alignScaleBorder( row, QwtPlot::yLeft );
alignScaleBorder( row, QwtPlot::yRight );
}
for ( int col = 0; col < numColumns(); col++ )
{
alignAxes( col, QwtPlot::yLeft );
alignAxes( col, QwtPlot::yRight );
alignScaleBorder( col, QwtPlot::xBottom );
alignScaleBorder( col, QwtPlot::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 ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight )
{
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 == QwtPlot::yLeft )
{
QwtPlot *p = plotAt( rowOrColumn, 0 );
if ( p )
p->axisWidget( axis )->getBorderDistHint( startDist, endDist );
for ( int col = 1; col < numColumns(); col++ )
{
QwtPlot *p = plotAt( rowOrColumn, col );
if ( p )
p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
}
}
else if ( axis == QwtPlot::yRight )
{
QwtPlot *p = plotAt( rowOrColumn, numColumns() - 1 );
if ( p )
p->axisWidget( axis )->getBorderDistHint( startDist, endDist );
for ( int col = 0; col < numColumns() - 1; col++ )
{
QwtPlot *p = plotAt( rowOrColumn, col );
if ( p )
p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
}
}
if ( axis == QwtPlot::xTop )
{
QwtPlot *p = plotAt( rowOrColumn, 0 );
if ( p )
p->axisWidget( axis )->getBorderDistHint( startDist, endDist );
for ( int row = 1; row < numRows(); row++ )
{
QwtPlot *p = plotAt( row, rowOrColumn );
if ( p )
p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
}
}
else if ( axis == QwtPlot::xBottom )
{
QwtPlot *p = plotAt( numRows() - 1, rowOrColumn );
if ( p )
p->axisWidget( axis )->getBorderDistHint( startDist, endDist );
for ( int row = 0; row < numRows() - 1; row++ )
{
QwtPlot *p = plotAt( row, rowOrColumn );
if ( p )
p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
}
}
}

View file

@ -0,0 +1,41 @@
#ifndef _PLOT_MATRIX_H_
#define _PLOT_MATRIX_H_
#include <qframe.h>
#include <qwt_plot.h>
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 enableAxis( int axisId, bool tf = true );
bool axisEnabled( 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 *d_data;
};
#endif

View file

@ -0,0 +1,19 @@
################################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
################################################################
include( $${PWD}/../playground.pri )
TARGET = plotmatrix
HEADERS = \
plotmatrix.h
SOURCES = \
plotmatrix.cpp \
main.cpp

View file

@ -0,0 +1,15 @@
#include <qapplication.h>
#include "mainwindow.h"
int main( int argc, char **argv )
{
QApplication a( argc, argv );
MainWindow mainWindow;
mainWindow.resize( 800, 600 );
mainWindow.show();
return a.exec();
}

View file

@ -0,0 +1,146 @@
#include <cstdlib>
#include <qgroupbox.h>
#include <qcombobox.h>
#include <qlayout.h>
#include <qstatusbar.h>
#include <qlabel.h>
#include <qwt_plot.h>
#include <qwt_plot_rescaler.h>
#include <qwt_scale_div.h>
#include "plot.h"
#include "mainwindow.h"
MainWindow::MainWindow()
{
QFrame *w = new QFrame( this );
QWidget *panel = createPanel( w );
panel->setFixedWidth( 2 * panel->sizeHint().width() );
d_plot = createPlot( w );
QHBoxLayout *layout = new QHBoxLayout( w );
layout->setMargin( 0 );
layout->addWidget( panel, 0 );
layout->addWidget( d_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 ) ) );
d_rescaleInfo = new QLabel( panel );
d_rescaleInfo->setSizePolicy(
QSizePolicy::Expanding, QSizePolicy::Expanding );
d_rescaleInfo->setWordWrap( true );
QVBoxLayout *layout = new QVBoxLayout( panel );
layout->addWidget( rescaleBox );
layout->addWidget( d_rescaleInfo );
layout->addStretch( 10 );
return panel;
}
Plot *MainWindow::createPlot( QWidget *parent )
{
Plot *plot = new Plot( parent, QwtInterval( 0.0, 1000.0 ) );
plot->replot();
d_rescaler = new QwtPlotRescaler( plot->canvas() );
d_rescaler->setReferenceAxis( QwtPlot::xBottom );
d_rescaler->setAspectRatio( QwtPlot::yLeft, 1.0 );
d_rescaler->setAspectRatio( QwtPlot::yRight, 0.0 );
d_rescaler->setAspectRatio( QwtPlot::xTop, 0.0 );
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
d_rescaler->setIntervalHint( axis, 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:
{
d_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:
{
d_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.";
d_rescaleInfo->setText( "Expanding" );
break;
}
case Fitting:
{
d_rescaler->setRescalePolicy( QwtPlotRescaler::Fitting );
const QwtInterval xIntv =
d_rescaler->intervalHint( QwtPlot::xBottom );
const QwtInterval yIntv =
d_rescaler->intervalHint( QwtPlot::yLeft );
rectOfInterest = QRectF( xIntv.minValue(), yIntv.minValue(),
xIntv.width(), yIntv.width() );
direction = QwtPlotRescaler::ExpandBoth;
info = "Fitting";
break;
}
}
d_plot->setRectOfInterest( rectOfInterest );
d_rescaleInfo->setText( info );
d_rescaler->setEnabled( doEnable );
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
d_rescaler->setExpandingDirection( direction );
if ( doEnable )
d_rescaler->rescale();
else
d_plot->replot();
}
void MainWindow::showRatio( double xRatio, double yRatio )
{
const QString msg = QString( "%1, %2" ).arg( xRatio ).arg( yRatio );
statusBar()->showMessage( msg );
}

View file

@ -0,0 +1,39 @@
#ifndef _MAINWINDOW_H_
#define _MAINWINDOW_H_ 1
#include <qmainwindow.h>
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 *d_rescaler;
QLabel *d_rescaleInfo;
Plot *d_plot;
};
#endif

View file

@ -0,0 +1,181 @@
#include "plot.h"
#include <qglobal.h>
#include <qpainter.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_layout.h>
#include <qwt_interval.h>
#include <qwt_painter.h>
#include <qwt_plot_item.h>
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
{
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
};
RectItem( Type type ):
d_type( type )
{
}
void setPen( const QPen &pen )
{
if ( pen != d_pen )
{
d_pen = pen;
itemChanged();
}
}
void setBrush( const QBrush &brush )
{
if ( brush != d_brush )
{
d_brush = brush;
itemChanged();
}
}
void setRect( const QRectF &rect )
{
if ( d_rect != rect )
{
d_rect = rect;
itemChanged();
}
}
virtual QRectF boundingRect() const
{
return d_rect;
}
virtual void draw( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF & ) const
{
if ( d_rect.isValid() )
{
const QRectF rect = QwtScaleMap::transform(
xMap, yMap, d_rect );
painter->setPen( d_pen );
painter->setBrush( d_brush );
if ( d_type == Ellipse )
QwtPainter::drawEllipse( painter, rect );
else
QwtPainter::drawRect( painter, rect );
}
}
private:
QPen d_pen;
QBrush d_brush;
QRectF d_rect;
Type d_type;
};
Plot::Plot( QWidget *parent, const QwtInterval &interval ):
QwtPlot( parent )
{
for ( int axis = 0; axis < QwtPlot::axisCnt; axis ++ )
setAxisScale( axis, 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() +
qrand() % qRound( interval.width() );
const double y = interval.minValue() +
qrand() % qRound( interval.width() );
const double r = interval.minValue() +
qrand() % 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 );
d_rectOfInterest = new RectItem( RectItem::Rect );
d_rectOfInterest->setPen( Qt::NoPen );
QColor c = Qt::gray;
c.setAlpha( 100 );
d_rectOfInterest->setBrush( QBrush( c ) );
d_rectOfInterest->attach( this );
}
void Plot::updateLayout()
{
QwtPlot::updateLayout();
const QwtScaleMap xMap = canvasMap( QwtPlot::xBottom );
const QwtScaleMap yMap = canvasMap( QwtPlot::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 )
{
d_rectOfInterest->setRect( rect );
}

View file

@ -0,0 +1,28 @@
#ifndef _PLOT_H_
#define _PLOT_H_ 1
#include <qwt_plot.h>
class RectItem;
class QwtInterval;
class Plot: public QwtPlot
{
Q_OBJECT
public:
Plot( QWidget *parent, const QwtInterval & );
virtual void updateLayout();
void setRectOfInterest( const QRectF & );
Q_SIGNALS:
void resized( double xRatio, double yRatio );
private:
RectItem *d_rectOfInterest;
};
#endif

View 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}/../playground.pri )
TARGET = rescaler
HEADERS = \
mainwindow.h \
plot.h
SOURCES = \
mainwindow.cpp \
plot.cpp \
main.cpp

View file

@ -0,0 +1,120 @@
#include "mainwindow.h"
#include "plot.h"
#include "transformplot.h"
#include <qwt_transform.h>
#include <qsplitter.h>
#include <qmath.h>
class TransformPos: public QwtTransform
{
public:
TransformPos( double pos, double range, double factor ):
d_position( pos ),
d_range( range ),
d_factor( factor ),
d_powRange( qPow( d_range, d_factor ) )
{
}
virtual double transform( double value ) const
{
const double v1 = d_position - d_range;
const double v2 = v1 + 2 * d_range;
if ( value <= v1 )
{
return value;
}
if ( value >= v2 )
{
return v1 + 2 * d_powRange + value - v2;
}
double v;
if ( value <= d_position )
{
v = v1 + qPow( value - v1, d_factor );
}
else
{
v = v1 + 2 * d_powRange - qPow( v2 - value, d_factor );
}
return v;
}
virtual double invTransform( double value ) const
{
const double v1 = d_position - d_range;
const double v2 = v1 + 2 * d_powRange;
if ( value < v1 )
{
return value;
}
if ( value >= v2 )
{
return value + 2 * ( d_range - d_powRange );
}
double v;
if ( value <= v1 + d_powRange )
{
v = v1 + qPow( value - v1, 1.0 / d_factor );
}
else
{
v = d_position + d_range - qPow( v2 - value, 1.0 / d_factor );
}
return v;
}
virtual QwtTransform *copy() const
{
return new TransformPos( d_position, d_range, d_factor );
}
private:
const double d_position;
const double d_range;
const double d_factor;
const double d_powRange;
};
MainWindow::MainWindow( QWidget *parent ):
QMainWindow( parent )
{
QSplitter *splitter = new QSplitter( Qt::Vertical );
d_transformPlot = new TransformPlot( splitter );
d_transformPlot->insertTransformation( "Square Root",
QColor( "DarkSlateGray" ), new QwtPowerTransform( 0.5 ) );
d_transformPlot->insertTransformation( "Linear",
QColor( "Peru" ), new QwtNullTransform() );
d_transformPlot->insertTransformation( "Cubic",
QColor( "OliveDrab" ), new QwtPowerTransform( 3.0 ) );
d_transformPlot->insertTransformation( "Power 10",
QColor( "Indigo" ), new QwtPowerTransform( 10.0 ) );
d_transformPlot->insertTransformation( "Log",
QColor( "SteelBlue" ), new QwtLogTransform() );
d_transformPlot->insertTransformation( "At 400",
QColor( "Crimson" ), new TransformPos( 400.0, 100.0, 1.4 ) );
const QwtPlotItemList curves =
d_transformPlot->itemList( QwtPlotItem::Rtti_PlotCurve );
if ( !curves.isEmpty() )
d_transformPlot->setLegendChecked( curves[ 2 ] );
d_plot = new Plot( splitter );
d_plot->setTransformation( new QwtPowerTransform( 3.0 ) );
setCentralWidget( splitter );
connect( d_transformPlot, SIGNAL( selected( QwtTransform * ) ),
d_plot, SLOT( setTransformation( QwtTransform * ) ) );
}

View file

@ -0,0 +1,16 @@
#include <qmainwindow.h>
class Plot;
class TransformPlot;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget *parent = 0 );
private:
Plot *d_plot;
TransformPlot *d_transformPlot;
};

View file

@ -0,0 +1,70 @@
#include "plot.h"
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <qwt_symbol.h>
#include <qwt_plot_picker.h>
#include <qwt_scale_engine.h>
Plot::Plot( QWidget *parent ):
QwtPlot( parent )
{
setCanvasBackground( Qt::white );
setAxisScale(QwtPlot::yLeft, 0.0, 10.0 );
setTransformation( new QwtNullTransform() );
populate();
QwtPlotPicker *picker = new QwtPlotPicker( canvas() );
picker->setTrackerMode( QwtPlotPicker::AlwaysOn );
}
void Plot::populate()
{
QwtPlotGrid *grid = new QwtPlotGrid();
grid->setMinorPen( Qt::black, 0, Qt::DashLine );
grid->enableXMin( true );
grid->attach( this );
QwtPlotCurve *curve = new QwtPlotCurve();
curve->setTitle("Some Points");
curve->setPen( Qt::blue, 4 ),
curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
curve->setSymbol( symbol );
QPolygonF points;
points << QPointF( 10.0, 4.4 )
<< QPointF( 100.0, 3.0 ) << QPointF( 200.0, 4.5 )
<< QPointF( 300.0, 6.8 ) << QPointF( 400.0, 7.9 )
<< QPointF( 500.0, 7.1 ) << QPointF( 600.0, 7.9 )
<< QPointF( 700.0, 7.1 ) << QPointF( 800.0, 5.4 )
<< QPointF( 900.0, 2.8 ) << QPointF( 1000.0, 3.6 );
curve->setSamples( points );
curve->attach( this );
}
void Plot::setTransformation( QwtTransform *transform )
{
QwtLinearScaleEngine *scaleEngine = new QwtLinearScaleEngine();
scaleEngine->setTransformation( transform );
setAxisScaleEngine( QwtPlot::xBottom, scaleEngine );
// we have to reassign the axis settinge, because they are
// invalidated, when the scale engine has changed
QwtScaleDiv scaleDiv =
axisScaleEngine( QwtPlot::xBottom )->divideScale( 10.0, 1000.0, 8, 10 );
QList<double> ticks;
ticks += 10.0;
ticks += scaleDiv.ticks( QwtScaleDiv::MajorTick );
scaleDiv.setTicks( QwtScaleDiv::MajorTick, ticks );
setAxisScaleDiv( QwtPlot::xBottom, scaleDiv );
replot();
}

View file

@ -0,0 +1,23 @@
#ifndef _PLOT_H_
#define _PLOT_H_
#include <qwt_plot.h>
class QwtTransform;
class Plot: public QwtPlot
{
Q_OBJECT
public:
Plot( QWidget *parent = NULL );
public Q_SLOTS:
void setTransformation( QwtTransform * );
private:
void populate();
};
#endif

View file

@ -0,0 +1,13 @@
#include <qapplication.h>
#include "mainwindow.h"
int main(int argc, char **argv)
{
QApplication a(argc, argv);
MainWindow window;
window.resize(800,600);
window.show();
return a.exec();
}

View file

@ -0,0 +1,24 @@
################################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
################################################################
include( $${PWD}/../playground.pri )
TARGET = scaleengine
HEADERS = \
transformplot.h \
plot.h \
mainwindow.h
SOURCES = \
transformplot.cpp \
plot.cpp \
mainwindow.cpp \
scaleengine.cpp

View file

@ -0,0 +1,108 @@
#include "transformplot.h"
#include <qwt_curve_fitter.h>
#include <qwt_plot_curve.h>
#include <qwt_point_data.h>
#include <qwt_transform.h>
#include <qwt_legend.h>
#include <qwt_legend_label.h>
class TransformData: public QwtSyntheticPointData
{
public:
TransformData( QwtTransform *transform ):
QwtSyntheticPointData( 200 ),
d_transform( transform )
{
}
virtual ~TransformData()
{
delete d_transform;
}
const QwtTransform *transform() const
{
return d_transform;
}
virtual double y( double x ) const
{
const double min = 10.0;
const double max = 1000.0;
const double value = min + x * ( max - min );
const double s1 = d_transform->transform( min );
const double s2 = d_transform->transform( max );
const double s = d_transform->transform( value );
return ( s - s1 ) / ( s2 - s1 );
}
private:
QwtTransform *d_transform;
};
TransformPlot::TransformPlot( QWidget *parent ):
QwtPlot( parent )
{
setTitle( "Transformations" );
setCanvasBackground( Qt::white );
setAxisScale( QwtPlot::xBottom, 0.0, 1.0 );
setAxisScale( QwtPlot::yLeft, 0.0, 1.0 );
QwtLegend *legend = new QwtLegend();
legend->setDefaultItemMode( QwtLegendData::Checkable );
insertLegend( legend, QwtPlot::RightLegend );
connect( legend, SIGNAL( checked( const QVariant &, bool, int ) ),
this, SLOT( legendChecked( const QVariant &, bool ) ) );
}
void TransformPlot::insertTransformation(
const QString &title, const QColor &color, QwtTransform *transform )
{
QwtPlotCurve *curve = new QwtPlotCurve( title );
curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
curve->setPen( color, 2 );
curve->setData( new TransformData( transform ) );
curve->attach( this );
}
void TransformPlot::legendChecked( const QVariant &itemInfo, bool on )
{
QwtPlotItem *plotItem = infoToItem( itemInfo );
setLegendChecked( plotItem );
if ( on && plotItem->rtti() == QwtPlotItem::Rtti_PlotCurve )
{
QwtPlotCurve *curve = static_cast<QwtPlotCurve *>( plotItem );
TransformData *data = static_cast<TransformData *>( curve->data() );
Q_EMIT selected( data->transform()->copy() );
}
}
void TransformPlot::setLegendChecked( QwtPlotItem *plotItem )
{
const QwtPlotItemList items = itemList();
for ( int i = 0; i < items.size(); i++ )
{
QwtPlotItem *item = items[ i ];
if ( item->testItemAttribute( QwtPlotItem::Legend ) )
{
QwtLegend *lgd = qobject_cast<QwtLegend *>( legend() );
QwtLegendLabel *label = qobject_cast< QwtLegendLabel *>(
lgd->legendWidget( itemToInfo( item ) ) );
if ( label )
{
lgd->blockSignals( true );
label->setChecked( item == plotItem );
lgd->blockSignals( false );
}
}
}
}

View file

@ -0,0 +1,27 @@
#ifndef _TRANSFORM_PLOT_H_
#define _TRANSFORM_PLOT_H_
#include <qwt_plot.h>
class TransformPlot: public QwtPlot
{
Q_OBJECT
public:
TransformPlot( QWidget *parent = NULL );
void insertTransformation( const QString &,
const QColor &, QwtTransform * );
void setLegendChecked( QwtPlotItem * );
Q_SIGNALS:
void selected( QwtTransform * );
private Q_SLOTS:
void legendChecked( const QVariant &, bool on );
private:
};
#endif

View file

@ -0,0 +1,100 @@
#include <qapplication.h>
#include <qpainterpath.h>
#include <qwt_plot.h>
#include <qwt_legend.h>
#include <qwt_point_data.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
#include <qwt_plot_shapeitem.h>
#include <qwt_scale_engine.h>
class Plot : public QwtPlot
{
public:
Plot( QWidget *parent = NULL );
private:
void populate();
};
Plot::Plot( QWidget *parent ):
QwtPlot( parent )
{
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
setAxisTitle( xBottom, "x -->" );
setAxisTitle( yLeft, "y -->" );
#if 0
setAxisScaleEngine( xBottom, new QwtLog10ScaleEngine );
setAxisScaleEngine( yLeft, new QwtLog10ScaleEngine );
#endif
populate();
}
void Plot::populate()
{
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, "Seppi" );
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
QwtPlotShapeItem *item = new QwtPlotShapeItem( "Shape" );
item->setItemAttribute( QwtPlotItem::Legend, true );
item->setRenderHint( QwtPlotItem::RenderAntialiased, true );
#if 1
item->setRenderTolerance( 1.0 );
#endif
item->setShape( path );
item->setPen( Qt::yellow );
QColor c = Qt::darkRed;
c.setAlpha( 100 );
item->setBrush( c );
item->attach( this );
}
int main( int argc, char **argv )
{
QApplication a( argc, argv );
Plot plot;
plot.resize( 600, 400 );
plot.show();
return a.exec();
}

View file

@ -0,0 +1,16 @@
################################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
################################################################
include( $${PWD}/../playground.pri )
TARGET = shapes
SOURCES = \
shapes.cpp

View file

@ -0,0 +1,49 @@
#include <qapplication.h>
#include <qmainwindow.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include "plot.h"
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
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() ), plot, SLOT( loadSVG() ) );
#endif
}
};
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QString fileName;
if ( argc > 1 )
fileName = argv[1];
MainWindow w( fileName );
w.resize( 600, 400 );
w.show();
int rv = a.exec();
return rv;
}

View file

@ -0,0 +1,79 @@
#include <qfiledialog.h>
#include <qwt_plot_svgitem.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_layout.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
#include "plot.h"
Plot::Plot( QWidget *parent ):
QwtPlot( parent ),
d_mapItem( NULL ),
d_mapRect( 0.0, 0.0, 100.0, 100.0 ) // something
{
#if 1
/*
d_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 axis = 0; axis < QwtPlot::axisCnt; axis++ )
enableAxis( axis, false );
#else
QwtPlotGrid *grid = new QwtPlotGrid();
grid->attach( this );
#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 );
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 ( d_mapItem == NULL )
{
d_mapItem = new QwtPlotSvgItem();
d_mapItem->attach( this );
}
d_mapItem->loadFile( d_mapRect, fileName );
rescale();
replot();
}
void Plot::rescale()
{
setAxisScale( QwtPlot::xBottom,
d_mapRect.left(), d_mapRect.right() );
setAxisScale( QwtPlot::yLeft,
d_mapRect.top(), d_mapRect.bottom() );
}

26
playground/svgmap/plot.h Normal file
View file

@ -0,0 +1,26 @@
#include <qwt_plot.h>
#include <qrect.h>
class QwtPlotSvgItem;
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();
QwtPlotSvgItem *d_mapItem;
const QRectF d_mapRect;
};

View file

@ -0,0 +1,26 @@
################################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
################################################################
include( $${PWD}/../playground.pri )
!contains(QWT_CONFIG, QwtSvg) {
message(Are you trying to build Qwt with the Qt Creator as Shadow Build ?)
error(Qwt is configured without SVG support !)
}
TARGET = svgmap
QT += svg
HEADERS = \
plot.h
SOURCES = \
plot.cpp \
main.cpp

View file

@ -0,0 +1,216 @@
#include <qapplication.h>
#include <qpainter.h>
#include <qbuffer.h>
#ifdef QT_SVG_LIB
#include <qsvggenerator.h>
#endif
#include <qwt_plot.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <qwt_symbol.h>
#include <qwt_graphic.h>
#include <qwt_legend.h>
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, 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;
}
};
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QwtPlot plot;
plot.setTitle( "Plot Demo" );
plot.setCanvasBackground( Qt::white );
plot.setAxisScale( QwtPlot::xBottom, -1.0, 6.0 );
QwtLegend *legend = new QwtLegend();
legend->setDefaultItemMode( QwtLegendData::Checkable );
plot.insertLegend( legend );
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( &plot );
}
plot.resize( 600, 400 );
plot.show();
return a.exec();
}

View file

@ -0,0 +1,16 @@
################################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
################################################################
include( $${PWD}/../playground.pri )
TARGET = symbols
SOURCES = \
symbols.cpp

View file

@ -0,0 +1,13 @@
#include <qapplication.h>
#include "mainwindow.h"
int main( int argc, char **argv )
{
QApplication a( argc, argv );
MainWindow window;
window.resize( 800, 600 );
window.show();
return a.exec();
}

View file

@ -0,0 +1,58 @@
#include "plot.h"
#include "panel.h"
#include "mainwindow.h"
#include <qwt_date.h>
#include <qwt_scale_widget.h>
#include <qlayout.h>
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;
d_plot = new Plot();
d_panel = new Panel();
d_panel->setSettings( settings );
QWidget *box = new QWidget( this );
QHBoxLayout *layout = new QHBoxLayout( box );
layout->addWidget( d_plot, 10 );
layout->addWidget( d_panel );
setCentralWidget( box );
updatePlot();
connect( d_panel, SIGNAL( edited() ), SLOT( updatePlot() ) );
connect( d_plot->axisWidget( QwtPlot::yLeft ),
SIGNAL( scaleDivChanged() ), SLOT( updatePanel() ) );
}
void MainWindow::updatePlot()
{
d_plot->blockSignals( true );
d_plot->applySettings( d_panel->settings() );
d_plot->blockSignals( false );
}
void MainWindow::updatePanel()
{
const QwtScaleDiv scaleDiv = d_plot->axisScaleDiv( QwtPlot::yLeft );
Settings settings = d_panel->settings();
settings.startDateTime = QwtDate::toDateTime( scaleDiv.lowerBound(), Qt::LocalTime );
settings.endDateTime = QwtDate::toDateTime( scaleDiv.upperBound(), Qt::LocalTime );
d_panel->setSettings( settings );
}

View file

@ -0,0 +1,20 @@
#include <qmainwindow.h>
class Plot;
class Panel;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget *parent = 0 );
private Q_SLOTS:
void updatePlot();
void updatePanel();
private:
Plot *d_plot;
Panel *d_panel;
};

View file

@ -0,0 +1,95 @@
#include "panel.h"
#include "settings.h"
#include <qwt_date.h>
#include <qdatetimeedit.h>
#include <qspinbox.h>
#include <qlayout.h>
#include <qlabel.h>
Panel::Panel( QWidget *parent ):
QWidget( parent )
{
// create widgets
d_startDateTime = new QDateTimeEdit();
d_startDateTime->setDisplayFormat( "M/d/yyyy h:mm AP :zzz" );
d_startDateTime->setCalendarPopup( true );
d_endDateTime = new QDateTimeEdit();
d_endDateTime->setDisplayFormat( "M/d/yyyy h:mm AP :zzz" );
d_endDateTime->setCalendarPopup( true );
d_maxMajorSteps = new QSpinBox();
d_maxMajorSteps->setRange( 0, 50 );
d_maxMinorSteps = new QSpinBox();
d_maxMinorSteps->setRange( 0, 50 );
d_maxWeeks = new QSpinBox();
d_maxWeeks->setRange( -1, 100 );
d_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( d_startDateTime, row, 1 );
row++;
layout->addWidget( new QLabel( "To" ), row, 0 );
layout->addWidget( d_endDateTime, row, 1 );
row++;
layout->addWidget( new QLabel( "Max. Major Steps" ), row, 0 );
layout->addWidget( d_maxMajorSteps, row, 1 );
row++;
layout->addWidget( new QLabel( "Max. Minor Steps" ), row, 0 );
layout->addWidget( d_maxMinorSteps, row, 1 );
row++;
layout->addWidget( new QLabel( "Max Weeks" ), row, 0 );
layout->addWidget( d_maxWeeks, row, 1 );
connect( d_startDateTime,
SIGNAL( dateTimeChanged( const QDateTime & ) ), SIGNAL( edited() ) );
connect( d_endDateTime,
SIGNAL( dateTimeChanged( const QDateTime & ) ), SIGNAL( edited() ) );
connect( d_maxMajorSteps,
SIGNAL( valueChanged( int ) ), SIGNAL( edited() ) );
connect( d_maxMinorSteps,
SIGNAL( valueChanged( int ) ), SIGNAL( edited() ) );
connect( d_maxWeeks,
SIGNAL( valueChanged( int ) ), SIGNAL( edited() ) );
}
void Panel::setSettings( const Settings &settings )
{
blockSignals( true );
d_startDateTime->setDateTime( settings.startDateTime );
d_endDateTime->setDateTime( settings.endDateTime );
d_maxMajorSteps->setValue( settings.maxMajorSteps );
d_maxMinorSteps->setValue( settings.maxMinorSteps );
d_maxWeeks->setValue( settings.maxWeeks );
blockSignals( false );
}
Settings Panel::settings() const
{
Settings settings;
settings.startDateTime = d_startDateTime->dateTime();
settings.endDateTime = d_endDateTime->dateTime();
settings.maxMajorSteps = d_maxMajorSteps->value();
settings.maxMinorSteps = d_maxMinorSteps->value();
settings.maxWeeks = d_maxWeeks->value();
return settings;
}

View file

@ -0,0 +1,32 @@
#ifndef _PANEL_
#define _PANEL_
#include "settings.h"
#include <qwidget.h>
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* d_startDateTime;
QDateTimeEdit* d_endDateTime;
QSpinBox *d_maxMajorSteps;
QSpinBox *d_maxMinorSteps;
QSpinBox *d_maxWeeks;
};
#endif

View file

@ -0,0 +1,90 @@
#include "plot.h"
#include "settings.h"
#include <qwt_date.h>
#include <qwt_date_scale_draw.h>
#include <qwt_date_scale_engine.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_layout.h>
Plot::Plot( QWidget *parent ):
QwtPlot( parent )
{
setAutoFillBackground( true );
setPalette( Qt::darkGray );
setCanvasBackground( Qt::white );
plotLayout()->setAlignCanvasToScales( true );
initAxis( QwtPlot::yLeft, "Local Time", Qt::LocalTime );
initAxis( QwtPlot::yRight,
"Coordinated Universal Time ( UTC )", Qt::UTC );
QwtPlotPanner *panner = new QwtPlotPanner( canvas() );
QwtPlotMagnifier *magnifier = new QwtPlotMagnifier( canvas() );
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
const bool on = axis == QwtPlot::yLeft ||
axis == QwtPlot::yRight;
enableAxis( 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( QwtPlot::yLeft, settings );
applyAxisSettings( QwtPlot::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 ) );
}

View file

@ -0,0 +1,23 @@
#ifndef _PLOT_H_
#define _PLOT_H_
#include <qwt_plot.h>
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 & );
};
#endif

View file

@ -0,0 +1,25 @@
#ifndef _SETTINGS_H_
#define _SETTINGS_H_ 1
#include <qdatetime.h>
class Settings
{
public:
Settings():
maxMajorSteps( 10 ),
maxMinorSteps( 5 ),
maxWeeks( -1 )
{
};
QDateTime startDateTime;
QDateTime endDateTime;
int maxMajorSteps;
int maxMinorSteps;
int maxWeeks;
};
#endif

View file

@ -0,0 +1,24 @@
################################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
################################################################
include( $${PWD}/../playground.pri )
TARGET = timescale
HEADERS = \
panel.h \
plot.h \
mainwindow.h
SOURCES = \
panel.cpp \
plot.cpp \
mainwindow.cpp \
main.cpp